Problem with getline in C++ programming

  • Comp Sci
  • Thread starter khotsofalang
  • Start date
  • #1

Homework Statement



I am solving a problem in which I am reading numbers from cells in a csv file, I used getline to get strings from the csv file then converted the string to an integer... but the getline seemingly discards the last cell in the csv file


Homework Equations



this my C++ code:
if (input_file.good()){
array= new int;
while(!input_file.eof()){getline(input_file,number,',');//input filename is istream
//problem seems to be with the getline discarding the last cell
if(input_file.good()){

//otherwise everything is okay except i nid that number in last cell

cout<<number<<endl;
stringstream convert(number);
convert>>num;
array=num;
// cout<<num;
i++;}}}

The Attempt at a Solution



I attempted the solution as above, please let me know if there is an effecient way to get all data from the file

Homework Statement





Homework Equations





The Attempt at a Solution

 

Answers and Replies

  • #2
631
0
I am not quite sure why this is happening (I mostly use C, almost never getline) but have you tried getc?
 

Related Threads on Problem with getline in C++ programming

  • Last Post
Replies
7
Views
2K
  • Last Post
Replies
2
Views
905
  • Last Post
Replies
1
Views
2K
Replies
0
Views
2K
  • Last Post
Replies
10
Views
1K
Replies
7
Views
5K
Replies
1
Views
3K
Top