引号符号解析

时间:2010-11-04 11:01:32

标签: c++

我有这样的文件

"a",205    
"b",214    
"c",223    
""",13

我需要解析它 我逐行读取到str,我必须将第二个字符从字符串转换为整数,但是当引用<“>字符时,它会抛出异常字符串下标超出范围

std::string STRING;
std::ifstream infile;
std::vector < std::string > tokens;
infile.open (Filename);

unsigned int x; 
while(! infile.eof()) 
{
    std::getline(infile,STRING); 
    tokens = Utility::splitString(STRING,',');//array of tokens
    x = (unsigned int)tokens[0][1];//convert first tokens,second character to uint
}

我认为它是逃脱序列的东西。

1 个答案:

答案 0 :(得分:1)

  1. tokens[0][1]获取第一个字符串的第二个字符,该字符超出范围。

  2. 类型转换不是转换的方式。使用atoi()。

相关问题