【发布时间】:2012-07-24 16:22:59
【问题描述】:
这可能以前出现过,但我不明白如何提取格式化数据。下面是我提取文本文件中字符串“[87]”和“[90]”之间所有文本的代码。
显然,[87] 和 [90] 的位置与输出中指示的位置相同。
void ExtractWebContent::filterContent(){
string str, str1;
string positionOfCurrency1 = "[87]";
string positionOfCurrency2 = "[90]";
size_t positionOfText1, positionOfText2;
ifstream reading;
reading.open("file_Currency.txt");
while (!reading.eof()){
getline (reading, str);
positionOfText1 = str.find(positionOfCurrency1);
positionOfText2 = str.find(positionOfCurrency2);
cout << "positionOfCurrency1 " << positionOfText1 << endl;
cout << "positionOfCurrency2 " << positionOfText2 << endl;
//str1= str.substr (positionOfText);
cout << "String" << str1 << endl;
}
reading.close();
货币文件更新:
[79]更多 »由于对欧元区经济的担忧,布伦特原油跌至 102 美元
市场数据
* Currencies
标题:货币
Name Price Change % Chg
[80]USD/SGD
1.2606 -0.00 -0.13%
USD/SGD [81]USDSGD=X
[82]EUR/SGD
1.5242 0.00 +0.11%
EUR/SGD [83]EURSGD=X
【问题讨论】:
-
您可能会喜欢my older answer,它使用 Boost 格式输出
-
我写了一个非常笼统的答案,应该会让你朝着正确的方向前进。如果您可以添加实际的文件格式,我可以更具体。
-
我已经更新了要提取内容的文本文件。看来 getline 是一个可能的解决方案。