2011-08-11 31 views
1

我試圖用C++從一個文件,它的結構是這樣讀閱讀:C++從多類型CSV文件的

frank, 80, 90 
johnny, 10, 25 
... 

我做了一個循環來遍歷文件的每一行,但每次我讀取名稱字符串時,逗號都包含在名稱中(因此代替frank我得到frank,)。

我有問題的代碼是:

// var declarations 
ifstream streamVar; 
string name; 
int num1, num2; 

// there is a chunk of code that opens file and does error checking here 

// this is the code that I'm having trouble with 
streamVar >> name; 
streamVar >> num1; 
streamVar.ignore(100, ','); 
streamVar >> num2; 

我怎樣才能而忽​​略了逗號閱讀這三個值?

+0

你可以發佈你用來閱讀文件的代碼嗎? –

+0

@Timo我用我正在使用的代碼更新了我的問題。 – Moses

回答

0

必須是因爲您的代碼錯誤。確切地說,由於你沒有發佈它,所以有人猜測。

我已經發布我使用的代碼爲read and write CSV files in C++。也許這會有所幫助。