C++ : How to skip first whitespace while using getline() with ifstream object to read a line from a file?

前端 未结 1 2010
迷失自我
迷失自我 2021-01-15 03:33

I have a file named \"items.dat\" with following contents in the order itemID, itemPrice and itemName.

item0001 500.00 item1 name1 with spaces
item0002 500.         


        
相关标签:
1条回答
  • 2021-01-15 04:04

    The std::ws IO manipulator can be used to discard leading whitespace.

    A compact way to use it is:

    getline(fileRead >> std::ws, tmpItem[i].name);
    

    This discards any whitespace from the ifstream before it's passed to getline.

    0 讨论(0)
提交回复
热议问题