如何打印出向量的內容?我想在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 關注
- 911 瀏覽
添加回答
舉報
0/150
提交
取消
