So far, I have managed to open the file and am able to place information into a separate txt file. The problem I am having is finding out how to manipulate the data within the file once it's open. Not so much write my own data into a txt file.
Also, I was reading some tips on using bubble sort to alphabetize the names within a certain column. I'm not quite sure if thats applicable here.
For example, I am given two columns within the txt file such that:
Student A
marci 1
dan 2
mike3
sam 4
Student B
kelly 2
zack 3
tony 4
rachel 5
I'd like to only alphabetize column A.
My code so far
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("Students.txt"); //opens txt file
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "File not found";
ofstream outputFile;
outputFile.open("StudentsNew.txt");
cout << " " << endl;
cout << "Writing data to the file" << endl;
//Writing to file
outputFile << "Testing!" << endl;
//Close file
outputFile.close();
cout << "Done" << endl;
cin.get();
cin.ignore();
return 0;
}
Can someone lead me into the right direction? Any tips would be great! Thank you

New Topic/Question
Reply




MultiQuote



|