getline undefined… reading multiple lines

一笑奈何 提交于 2019-12-25 06:25:47

问题


i have spent hours trying to get this to work and have been all over your website and nothing is working for me.....

basically i am working on a banking system for an assignment and this is the final thing that i need to do in order to complete my unit.

i am trying to read multiple lines from within a text file so i can output them. these will be my previous transactions.

i have managed to get it to store my values but i cannot, for the life of me, read the lines due to the fact that the "getline" code doesnt work. here is my code

static int linecount = 0 ;
ifstream readTransactions;
readTransactions.open("deposit");
string line ;
if ( readTransactions ) 
{
    while (getline (readTransactions , line ) ) {
    cout<<linecount<<": "<<line<<'\n';//supposing '\n' to be line end
    linecount++ ;
}
readTransactions.close( ) ;
return 0 ;

回答1:


You probably forgot to include the string header:

#include <string>



回答2:


if ( readTransactions ) has no problem. I want to know if 'reading multiple lines' means you see multiple lines are outputing on screen once. If yes, try endl instead of '\n'.



来源:https://stackoverflow.com/questions/21727206/getline-undefined-reading-multiple-lines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!