1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Problem with getline in C++ programming

  1. Sep 4, 2012 #1
    1. The problem statement, all variables and given/known data

    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

    2. Relevant 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

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

    stringstream convert(number);
    // cout<<num;

    3. 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
    1. The problem statement, all variables and given/known data

    2. Relevant equations

    3. The attempt at a solution
  2. jcsd
  3. Sep 4, 2012 #2
    I am not quite sure why this is happening (I mostly use C, almost never getline) but have you tried getc?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook