0
我试图解析具有以下信息解析C++中的文件,而忽略某些字符
test_wall ; Comments!!
je,5
forward
goto,1
test_random;
je,9
我应该忽略后注释文件中的“;”并转到下一行。当有逗号时,我试图忽略逗号并存储第二个值。
string c;
int a;
c=getChar();
ifstream myfile (filename);
if (myfile.is_open())
{
while (c != ';' && c != EOF)
{
c = getchar();
if(c == ',')
{
a= getChar();
}
}
}
myfile.close();
}
你的'getchar'调用没有引用流 - 它们将等待标准输入(例如键盘)。 – 2013-04-18 05:18:00
我怎样才能忽略逗号呢? – 2013-04-18 05:24:51
看来你需要'std :: string line; while(getline(myfile,line){std :: string :: size_type comma_pos = line.find(','); std :: string :: size_type semicolon_pos = line.find(';'); if(pos!= std :: string :: npos &&(semicolon_pos == std :: string :: npos || semicolon_pos> comma_pos))store(line [comma_pos + 1]);}' – 2013-04-18 05:47:27