[英]How do I store each value in a 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, "|", "|", &cPos)) != blank )
{
cout << currentValue << endl;
}
system("sleep 5");
return 0;
}
上面的代碼輸出以下值:
如何將上述每個值存儲在自己的字符串中?
顯而易見的答案是使用std::vector<std::string>
,如下所示:
string currentValue;
std::vector<std::string> addresses;
while( currentValue.assign(gfd.rawParse(data, "|", "|", &cPos)) != blank )
addresses.push_back(currentValue);
創建一個字符串向量,將每個新條目添加到末尾。
std::vector<std::string> strings;
strings.push_back(current_value);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.