okay i need to sort a string array by the first letter of the strings.
i read the input from a file and then into a different file
Code://this program // //program4.cpp //my name. (im not going to tell you this) #include <fstream> #include <iostream> #include <string> using namespace std; // using standard namespace int main () { char file[20]; string stri; string str[] = 100; int quit =24; cout << "enter the name of the input file in the format filename.txt: " ; //user determines the file to write to cin >> file; cout << endl; fstream myfil (file); if (myfil.is_open()) { quit=0; } else quit=1; while (quit==1) // keeps the user from trying to write in a close file { cout << "file could not be opened. enter the name of another file in the format filename.txt:" ; //error message cin >> file; fstream myfil ("example.txt"); if (myfil.is_open()) { quit=0; } } for (intx=1; x<=100; x++) myfil >> stri[x-1]; //^ here is my problem //i need to sort this string // // // cout << "enter the name of the output file in the format filename.txt: " ; //user determines the file to write to cin >> file; ofstream myfile (file); if (myfile.is_open()) { quit=0; } else quit=1; while (quit==1) // keeps the user from trying to write in a close file { cout << "file could not be opened. enter the name of another file in the format filename.txt: " ; //error message cin >> file; ofstream myfile ("example.txt"); if (myfile.is_open()) { quit=0; } } while (myfil) { myfil >> str; myfile <<str << endl; } myfile.close(); myfil.close();// close the file return 0; }



LinkBack URL
About LinkBacks



ut);