Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何将每个值存储在字符串中?_C++_String - Fatal编程技术网

C++ 如何将每个值存储在字符串中?

C++ 如何将每个值存储在字符串中?,c++,string,C++,String,我知道这段代码正在迭代并从文件中获取数据,但我想将每个值存储在它自己的独立字符串中 int getHosts() { system("clear"); GfdOogleTech gfd; string data = gfd.GetFileContents("./vhosts.a2m"); size_t cPos = 0 string currentValue; while( currentValue.assign(gfd.rawParse(data

我知道这段代码正在迭代并从文件中获取数据,但我想将每个值存储在它自己的独立字符串中

int getHosts()
{
    system("clear");
    GfdOogleTech gfd;
    string data = gfd.GetFileContents("./vhosts.a2m");
    size_t cPos = 0
    string currentValue;
    while( currentValue.assign(gfd.rawParse(data, "|", "|", &cPos)) != blank )
    {
         cout << currentValue << endl;
    }
    system("sleep 5");
    return 0;
}
intgethosts()
{
系统(“清除”);
gfd;
字符串数据=gfd.GetFileContents(“./vhosts.a2m”);
大小\u t cPos=0
字符串当前值;
while(currentValue.assign(gfd.rawParse(数据,“|”、“|”、&cPos))!=blank)
{

cout显而易见的答案是使用一个
std::vector
,类似这样:

string currentValue;
std::vector<std::string> addresses;

while( currentValue.assign(gfd.rawParse(data, "|", "|", &cPos)) != blank )
     addresses.push_back(currentValue);
字符串当前值;
向量地址;
while(currentValue.assign(gfd.rawParse(数据,“|”、“|”、&cPos))!=blank)
地址。推回(当前值);

创建字符串向量,将每个新条目添加到末尾

std::vector<std::string> strings;
strings.push_back(current_value);
std::向量字符串;
字符串。向后推_(当前_值);
只需在while循环之前声明一个std::vector并在其中返回currentValue?除非我遗漏了非常明显的东西:S