void makeNeat(ifstream& messyFile, ofstream& neatFile, int numberAfterDecimalpoint, int fieldWidth);
int main() {
ifstream fin;
ofstream fout;
fin.open("rawdata.txt");
if(fin.fail()) exit(1);
fout.open("neat.file");
if(fout.fail()) exit(1);
makeNeat(fin, fout, 5, 12);
fin.close();
fout.close();
return 0;
}
void makeNeat(ifstream& messyFile, ofstream& neatFile, int numberAfterDecimalpoint, int fieldWidth) {
neatFile.setf(ios::fixed);
neatFile.setf(ios::showpoint);
neatFile.setf(ios::showpos);
neatFile.precision(numberAfterDecimalpoint);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.setf(ios::showpos);
cout.precision(numberAfterDecimalpoint);
double next;
while (messyFile >> next) {
cout << setw(fieldWidth) << next << endl;
neatFile << setw(fieldWidth) << next << endl;
}
}
void addPlusPlus(ifstream& inStream, ofstream& outStream);
int main() {
ifstream fin;
ofstream fout;
cout << "Begin Editing Files. \n";
fin.open("cad.txt");
if(fin.fail()) exit(1);
fout.open("cppad.txt");
if(fout.fail()) exit(1);
addPlusPlus(fin, fout);
fin.close();
fout.close();
return 0;
}
void addPlusPlus(ifstream& inStream, ofstream& outStream) {
char next;
inStream.get(next);
while(!inStream.eof()) {
if(next == 'C')
outStream << "C++";
else
outStream << next;
inStream.get(next);
}
}
int main() {
stringstream ss;
string scores = "Luigi 70 100 90";
ss.str("");
ss.clear();
ss << scores;
string name = "";
int total = 0, count = 0, average = 0;
int score;
ss >> name;
while (ss >> score) {
count++;
total += score;
}
if(count > 0) {
average = total / count;
}
ss.clear();
ss.str("");
ss << "Name : " << name << " Average : " << average;
cout << ss.str() << endl;
return 0;
};
int main() {
stringstream ssList, ssNum;
string numbers = "1.1, 1.2, 1.3";
double total = 0;
double num;
ssList.clear();
ssList.str(numbers);
string field;
while (getline(ssList, field, ',')) {
ssNum.clear();
ssNum.str(field);
cout << ssNum.str() << endl;
ssNum >> num;
total += num;
}
cout << total << endl;
}