开发者

How do I store each value in a string?

I am aware that this code is iterating through and getting the data from the file but I want to store each value in it's own independent 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;
}

The code above outputs the following values:

  • crativetech.me.conf
  • www.creativetech.me
  • webmaster@creativetech.me
  • /web/creativetech/www

How do I store each one of the above values in it's own string?


The obvious answer would be with a std::vector<std::string>, something like this:

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

while( currentValue.assign(gfd.rawParse(data, "|", "|", &cPos)) != blank )
     addresses.push_back(currentValue);


Create a vector of strings, add each new entry to the end.

std::vector<std::string> strings;
strings.push_back(current_value);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜