»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 10-06-2003, 08:02 AM   #1 (permalink)
Registered User
 
Join Date: Oct 2003
Posts: 1
jsmith1017 is on a distinguished road
C++ abnormal program termination

Can someone look at this code and tell me what is wrong with it?

I get the message.....

abnormal program termination!

I think it has to do with the while loop and the Substr function.

If I take out the while loop it will work but only on one line.



Code....
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
#include <iomanip>
using namespace std;

int main ()
{
string inf;
string ouf;

cout << "What is the input file?\n";
cin >> inf; // Input File Name
cout << "What is the output file?\n";
cin >> ouf; // Output File Name

string Field;
string s;

ifstream fin(inf.c_str());
ofstream fout(ouf.c_str());

while (fin){

getline(fin, Field, '\n');

s = Field.substr(5, 16);

fout <<s <<endl; //output last name

} //End while loop
fin.close();
fout.close();

return 0;
}

jsmith1017 is offline   Reply With Quote
Old 10-06-2003, 11:32 AM   #2 (permalink)
Registered User
 
Join Date: Apr 2002
Posts: 58
JohnRoboto is on a distinguished road
Without being able to compile and execute your program until I get home, ya I would take a look at that loop and your substr.

You have Visual Studio or another IDE? You should try out the debugger if you haven't already; it will be your new best friend.
JohnRoboto is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 02:43 AM.