我徒劳地试图找到一种方法来解析存储在string
对象中的文本文件。字符串的格式如下:
...
1 45
1 46
1 47
2 43
2 44
2 45
...
我正在尝试遍历整个字符串,抓取每一行,然后将字符串除以第一个整数和第二个整数以进行进一步处理。但是,这样做是行不通的:
string fileContents;
string::iterator index;
for(index = fileContents.begin(); index != fileContents.end(); ++index)
{
cout << (*index); // this works as expected
// grab a substring representing one line of the file
string temp = (*index); // error: trying to assign const char to const char*
}
我正在尝试找到一种方法来做到这一点,但到目前为止我还没有运气。