0
poornaMoksha's Avatar, Join Date: Jan 2011
Ambitious contributor
Ok, if thats the case, just change the 'default' case to :

Code: c++
default: StudentID=inputstring.substr(start,inputstring.length()-start);

and the try once again

Last edited by poornaMoksha; 13Sep2011 at 16:19.. Reason: updated the fix
0
addision's Avatar, Join Date: Sep 2011
Light Poster
Nope that didn't work either.

I think I found a problem, when the program reaches the end of my .txt file list it appears to go back to my text file one more time and it returns an empty string right here:


getline (myfile,line);

string inputstring (line);


What I would like to do is test this each time to determine if the string is empty and if so then

system ("pause");
return 0;

I have tried both of these and my program completely disregards them:

if (inputstring.empty ()); AND
if (inputstring == "");

Neither appear to work.
0
poornaMoksha's Avatar, Join Date: Jan 2011
Ambitious contributor
give me the logs(upto the point at which crash occurs) after running the following :
Code: c++
#include <iostream>
#include <string>
#include <fstream>
using namespace std;


int main(int argc, char* argv[])
{
string inputstring;
string line;
ifstream myfile ("C:\\W04In.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout<<"DEBUG::"<<line;
cout<<"\n";
string inputstring (line);

string FirstName,MiddleInitial,LastName,StudentID;
size_t start, end;
start = 0; //initial start value

for (int counter=0;counter<4;counter++)
{
end=inputstring.find_first_of(",", start);
switch(counter)
{
case(0): {FirstName=inputstring.substr(start,end); cout<<"\n DEBUG:: Firstname done\n";}
break;
case(1): MiddleInitial=inputstring.substr(start,end-start); cout<<"\n DEBUG:: MiddleInitial done\n";}
break;
case(2): LastName=inputstring.substr(start,end-start); cout<<"\n DEBUG:: LastName done\n";}
break;
default: StudentID=inputstring.substr(start,inputstring.length()-start); cout<<"\n DEBUG:: studentID done\n";}
}
cout<<"DEBUG::"<<"start="<<start<<"end="<<end<<"strLen="<<inputstring.length();
cout<<"\n\n";
start=end+1;
}
string NewStudentID=StudentID.substr(2,3);
cout << LastName << ", " << FirstName<< ", "<< FirstName <<LastName<<StudentID<<"@student.college.net\n\n ";
cout << LastName << ", " << FirstName<< ", "<< FirstName <<LastName<<NewStudentID<<"@student.college.net\n\n ";
//pare down StudentID to the last three numbers
//concatonate strings to make email address
//output to file
}

//myfile.close();
}

else cout << "Unable to open file";

system ("pause");
return 0;
}

Sorry as Windows PC was unavailable at my home so could not compile and chk the changes, please correct some compile time errors (if any) and share me the logs.

Last edited by poornaMoksha; 14Sep2011 at 06:46..