Hi again everyone. I'm having a problem with some code I am writing. I need to take an input file change what is on it, then print out to the screen. What I want to change in the file is re-formatting it so that there is Last name First name then 10 scores, if there are less than ten scores replace the empty ones with 0's. here is what I got so far...
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
string getLast(string line);
bool moreToRead(istream& ins);
int main()
{
string line;
ifstream in;
{ in.open("in.text");
if (in.fail()) {
cerr << "Failed to open in.text.\n";
exit(1);
}
}
while(moreToRead(in)) {
getline(in, line);
getLast(line);
cout << line << endl;
}
in.close();
return (0);
}
// Function writen by William Austad
bool moreToRead(istream& ins) {
char ch;
ins.get(ch);
while(!ins.eof()) {
if (!isspace(ch)) {
ins.putback(ch);
return (true);
} else {
ins.get(ch);
}
}
return (false);
}
string getLast(string line) {
string temp = line;
stringstream tempStream;
string token;
if (tempStream >> token) {
return (token);
} else {
temp = "Error";
}
return (temp);
}
this is just a start, but could someone advise me where to go with this, I am kind of at a standstill.