I am having quite a bit of trouble. I can parse a string that I have read from a line of a text file using substr, however, when I want to further extract characters from one component of the parsed string "StudentID" (using another substr) I always get errors.
I have attempted the following to get the last three characters of a 5 digit student ID; NewStudentID=StudentID.substr(2,3). This does not work.
Also, when I output to the screen, the loop appears to continue to run for one or two cycles and outputs blank characters. I don't understand why. Can anyone help me out with this?
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(int argc, char* argv [])
{
string inputstring;
string line;
ifstream myfile ("W04In.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << LastName << ", " << FirstName<< ", "<< FirstName <<LastName<<StudentID<<"@student.college.net\n\n";
//pare down StudentID to the last three numbers
//concatonate strings to make email address
//output to file
}