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