Very beginner - Reading a fixed number of characters in a line C++ -


this pretty basic question i've started in c++. read 20 characters of line file (text). example:

wayne, bruce        0000000 

i want save "wayne, bruce" , spaces following string. i've been trying while , can't figure out how go this. such, if me out, ask answer kept simple. tried googling , think found answers, of them way on head. thank you.

#include <algorithm> #include <fstream> #include <string>  int main() {     std::string str;     std::ifstream file("test.txt");      std::copy_n(         std::istreambuf_iterator<char>(file),         20,         std::back_inserter(str)     ); } 

note isn't safe if file in question has less 20 chars.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -