简体   繁体   中英

getline undefined… reading multiple lines

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 ;

您可能忘记了包含string标头:

#include <string>

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'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM