小编Fac*_*doJ的帖子

字符串的C++向量,为什么赋值结果相同的char引用?

我目前正在学习C++,我想手动将值输入到字符串向量中,在存储之前处理每个字符.这是我使用的代码:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int i, height = 5, width = 5;
    vector<string> lab;
    lab.resize(height, "");
    string s;

    //For input reference
    cout << endl << "Input data:" << endl << "01234" << endl;

    //Input values
    for (i = 0; i < height; i++)
    {
        getline (cin, s);

        for (int j = 0; j < width; j++) 
        {   
            //Process char [...]
            lab[i][j] = s.at(j);
        }
    }

    //Show Matrix
    cout << endl << …
Run Code Online (Sandbox Code Playgroud)

c++ string pointers vector char

1
推荐指数
1
解决办法
143
查看次数

标签 统计

c++ ×1

char ×1

pointers ×1

string ×1

vector ×1