reading in information from a text file
i am reading in information from a text file, I am using ifstream, but this takes in every line, how to i read one line at a time, where the program will move to the start of new line each time, also i won't know how many lines will be in the file as it will be different each time.
Thankyou for any help.
to read a complete line from an input steam, use std::getline http://www.cplusplus.com/reference/string/getline/
for example, the following program reads lines one by one from the file and prints each line, with a line number, on stdout.
std::ifstream file( __FILE__ ) ;
std::string aline ;
int n = 0 ;
while( std::getline( file, aline ) )
std::cout << ++n << ". " << aline << '\n' ;
By RPeare in forum VB Classic
Last Post: 08-17-2007, 07:50 PM
Last Post: 08-14-2005, 12:07 PM
By Paolo in forum VB Classic
Last Post: 01-08-2001, 09:59 AM
By Ted Young in forum VB Classic
Last Post: 08-16-2000, 09:55 AM
By Gabriele in forum Java
Last Post: 05-03-2000, 04:38 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center