1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;
int get_file (ifstream& in, ofstream& out, string filename, string output); //this function opens the input file and output file and checks to see if they are open
void get_line (ifstream& in, ofstream& out); //this function brings the input file into a string and then changes all lowercase letters to uppercasse and leaves uppercase letters alone and changes digits to a * symbol then outputs its a$
//void name (ifstream& in, ofstream& out);
//void salary (ifstream& in, ofstream& out);
int main () {
ifstream in; //instream
ofstream out; //outstream
string filename, output; //input and output file
get_file (in, out, filename, output);
get_line (in, out);
// name (in, out);
// salary (in, out);
}
int get_file (ifstream& in, ofstream& out, string filename, string output) {
cout << "enter the file you would like to open" << endl;
cin >> filename; //takes in the name of the file your opening
in.open (filename.c_str()); //opens the file
if (in.fail()) { //checks to see if the file is open
cout << "that is not a file" << endl;
return 0;
}
cout << "Input the name of the output file" << endl;
cin >> output;
out.open (output.c_str());
if (in.fail()) {
cout << "that is not a file" << endl;
return 0;
}
}
void get_line (ifstream& in, ofstream& out) {
string line;
while (getline (in, line)){ // using getline to read in a single line at a time
for (int i = 0; i < 100; i++) {
out << line [i] << endl;
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if (line [i].at(0) < line [j].at(0)) {
string tmp = line [i];
line [i] = line [j];
line [j] = tmp;
}
}
}
out<< endl;
for (unsigned int i = 0; i < 100; i++) {
cout << line [i] << endl;
}
// out << line << endl; //output the whole string to the output file
}
in.close (); //closes the input file
out.close (); //closes the output file
}
|