相关疑难解决方法(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万
查看次数

boost :: algorithm :: join的一个很好的例子

我最近想使用boost :: algorithm :: join但我找不到任何用法示例,我不想花很多时间学习Boost Range库只是为了使用这个函数.

任何人都可以提供一个如何在字符串容器上使用连接的好例子吗?谢谢.

c++ string boost join

112
推荐指数
2
解决办法
7万
查看次数

将vector <int>转换为字符串

我有一个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)

c++ vector tostring

85
推荐指数
8
解决办法
9万
查看次数

标签 统计

c++ ×3

vector ×2

boost ×1

cout ×1

join ×1

output ×1

stdvector ×1

string ×1

tostring ×1