Hello guys!
can you give me an example on how to switch lines or records inside a textfile? I need to enter 2 numbers, there are 3 numbers inside the textfile, which also means it has 3 lines.
1 name
2 name
3 name
1st number entered= 2
2nd number entered=1
after entering those numbers, the notepad should look like this
2 name
1 name
3 name
I think this needs looping and array, and i'm not that good in making loops or array.
Here's my read code btw,
#include <iostream>
using std::cerr;
using std::cout;
using std::endl;
using std::fixed;
using std::ios;
using std::left;
using std::right;
using std::showpoint;
#include <fstream>
using std::ifstream;
#include<iomanip>
using std::setw;
using std::setprecision;
#include <string>
using std::string;
#include <cstdlib>
void outputLine( int, const string );
int main()
{
ifstream inClientFile("clients.txt", ios::in );
if ( !inClientFile )
{
cerr<< "File could not be opened"<<endl;
exit( 1 );
}
int account;
char name[30];
cout<< left << setw( 10 ) << "Account" << setw( 13 )
<< "Name"<< endl << fixed << showpoint;
while ( inClientFile >> account >> name )
outputLine( account, name);
return 0;
}
void outputLine( int account, const string name )
{
cout << left << setw(10) << account << setw(13) << name << endl;
}
I really need a good example that will help me understand how to do it.. thanks!