Obsługa plików, przepisywanie danych z jednego do drugiego pliku
Ostatnio zmodyfikowano 2017-01-03 20:01
CTRL85 Temat założony przez niniejszego użytkownika |
» 2017-01-03 18:16:25 3 napis trzeci c 1 234 56.789 0 12 3.45 1 6 -7.89 1 123 0 1 napis pierwszy a 0 123 12.11 0 12 1.12 0 2 -2.22 0 121 0 2 napis drugi b 1 334 3.3444 1 34 3.43 1 4 -4.34 1 234 0 1 napis pierwszy a 0 123 12.11 0 12 1.12 0 2 -2.22 0 121 0 2 napis drugi b 1 334 3.3444 1 34 3.43 1 4 -4.34 1 234 0 3 napis trzeci c 1 234 56.789 0 12 3.45 1 6 -7.89 1 123 0
|
|
mokrowski |
» 2017-01-03 20:01:33 #include <iostream> #include <fstream> #include <string>
using namespace std;
typedef struct { unsigned counter; string data; } record_t;
record_t copyRecord( ifstream & srcFile ) { record_t answer; answer.data = string(); string line; srcFile >> answer.counter; line += to_string( answer.counter ); line += '\n'; for( size_t i = 0; i < 7; ++i ) { getline( srcFile, line ); answer.data += line; answer.data += "\n"; } answer.data.erase( answer.data.size() - 1, 1 ); return answer; }
int main() { ifstream inputFile( "data.txt" ); auto r1 = copyRecord( inputFile ); auto r2 = copyRecord( inputFile ); auto r3 = copyRecord( inputFile ); ofstream outputFile( "output.txt" ); }
|
|
1 « 2 » |