相关疑难解决方法(0)

如何打印出矢量的内容?

我想用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)

c++ cout vector stdvector output

251
推荐指数
11
解决办法
64万
查看次数

标签 统计

c++ ×1

cout ×1

output ×1

stdvector ×1

vector ×1