如何打印出向量的内容?我想在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 0;
}}如何将向量的内容打印到屏幕上?
3 回答
莫回无
TA贡献1865条经验 获得超7个赞
#include <iostream>#include <algorithm> // for copy#include <iterator> // for ostream_iterator#include <vector>int main() { /* Set up vector to hold chars a-z */ std::vector<char> path; for (int ch = 'a'; ch <= 'z'; ++ch) path.push_back(ch); /* Print path vector to console */ std::copy(path.begin(), path.end(), std::ostream_iterator<char>(std::cout, " ")); return 0;}
char
). cout
" "
- 3 回答
- 0 关注
- 862 浏览
添加回答
举报
0/150
提交
取消