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
Post a Comment