我想用C++打印出一个向量的内容,这就是我所拥有的:
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <sstream>
#include <cstdio>
using namespace std;
int main()
{
ifstream file("maze.txt");
if (file) {
vector<char> vec(istreambuf_iterator<char>(file), (istreambuf_iterator<char>()));
vector<char> path;
int x = 17;
char entrance = vec.at(16);
char firstsquare = vec.at(x);
if (entrance == 'S') {
path.push_back(entrance);
}
for (x = 17; isalpha(firstsquare); x++) {
path.push_back(firstsquare);
}
for (int i = 0; i < path.size(); i++) {
cout << path[i] << " ";
}
cout << endl;
return …
Run Code Online (Sandbox Code Playgroud) 我最近想使用boost :: algorithm :: join但我找不到任何用法示例,我不想花很多时间学习Boost Range库只是为了使用这个函数.
任何人都可以提供一个如何在字符串容器上使用连接的好例子吗?谢谢.
我有一个vector<int>
有整数的容器(例如{1,2,3,4}),我想转换为表格的字符串
"1,2,3,4"
Run Code Online (Sandbox Code Playgroud)
在C++中最干净的方法是什么?在Python中,我就是这样做的:
>>> array = [1,2,3,4]
>>> ",".join(map(str,array))
'1,2,3,4'
Run Code Online (Sandbox Code Playgroud)