2010-11-04 51 views
0

我有這樣報價符號解析

"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 
}

我認爲這是一些與轉義序列。

+2

一個稍大的代碼片段將在這裏幫助。什麼是str [0] [1]應該是?這是一個二維字符串嗎? – 2010-11-04 11:04:08

+1

什麼是你的兩個指標?什麼具體的數據類型是'str'的?你能否提供更多的代碼? – Flinsch 2010-11-04 11:04:38

+0

你有沒有看過'STRING'和'token'的內容? – Flinsch 2010-11-04 11:13:32

回答

1
  1. tokens[0][1]獲取第一個字符串的第二個字符,該字符超出範圍。

  2. 類型轉換不是轉換的方式。使用atoi()。

+0

我想,他正在尋找字符的ASCII值,並不想將一個數字的字符串表示「轉換」爲一個整數。 – Flinsch 2010-11-04 11:16:48

+0

哦,謝謝所有這些都是我的錯我沒有注意到,在文件中有一行包含「,」,我分裂字符串',' – tga 2010-11-04 11:22:03