|
-
Dec 9th, 2002, 04:32 AM
#1
Thread Starter
Junior Member
Reading lines from a file.
Hi,
I wrote a function where I want to read 2 lines from a file. Each line will be soimething like
A + B - C
A - B + A - D - F
etc
I wrote a function as follows:
Code:
void GetData(string& Infix, string& Pre)
{
ifstream ins;
ins.open("data.txt");
char buffer[80];
int Count = 0; // Counter used to update position in array where we are saving the floppies contents to.
string data;
string FloppyData[2];
while(!ins.eof()){
getline(ins,data);
FloppyData[Count] = data;
Count++;
}
Infix = FloppyData[0];
Pre = FloppyData[1];
}
I can't see whats wrong with it. I want the FloppyData array to hold two strings, then assign Infix and Pre to the right values in the array.
Thanks in advance for any feedback.
-
Dec 11th, 2002, 11:26 AM
#2
Junior Member
Reply
All I did to get your code working is specified an absolute path to the file
Code:
#include "iostream"
#include "string"
#include "fstream"
using namespace std;
void GetData(string& Infix, string& Pre)
{
ifstream ins("c:\\data.txt");
int Count = 0; // Counter used to update position in array where we are saving the floppies contents to.
string data;
string FloppyData[2];
while(!ins.eof()){
getline(ins,data);
FloppyData[Count] = data;
Count++;
}
Infix = FloppyData[0];
Pre = FloppyData[1];
}
int main()
{
string i,p;
GetData(i,p);
cout << i << endl;
cout << p;
system("Pause");
return 0;
}
-
Dec 11th, 2002, 06:04 PM
#3
Thread Starter
Junior Member
I can compile that, but when I try to run it comes up with a pop up message saying - btw, I wouldn't have a clue where the created error log is.
Program Error
file.exe has generated errors and will be closed by Windows.
An error log is being created.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|