- 论坛徽章:
- 0
|
回复 #1 liht1981 的帖子
问题已经解决,但是导致这个问题的原因还没弄清楚,看来把string对象像数组一样操作是有问题的。
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
int main(void)
{
vector<string> v;
char input;
ifstream in("input");
if(in==NULL)
{
cout<<"can not open the file"<<endl;
return -1;
}
string line, total_line;
while(getline(in, line))
v.push_back(line);
for(int i=0; i<v.size()-1; i++)
{
total_line = total_line + v;
}
int position = total_line.find("CRC");
int i=0;
string CRC, CRC_rev;
while(('0'<=total_line[position-i-2]) && (total_line[position-i-2]<='9'))
i++;
CRC = total_line.substr(position-1-i, i);
cout<<CRC<<endl;
}
[ 本帖最后由 liht1981 于 2008-1-17 13:27 编辑 ] |
|