c++ - Read first n letters from file to a string? -


i'm quite new programming, , i'm doing exercise should use cycle read 25 first symbols file, contains string of 25 letters (+spaces if name shorter 25) , 2 numbers. example:

whirlpool machine         324 789.99 

as imagine should this:

ifstream info("information.txt"); string str; int a; double b; for(int = 0; < 25; i++) { // kind of code first 25 symbols string. } info >> >> b; 

and can't seem find right code 25 characters straight string. suggestions?

an easy way use read() read given number of characters:

int length = 25;             // num of chars want read str.resize(length, ' ');     // reserve spaces char* begin = &*str.begin(); info.read(begin, length);    // <- read here 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -