Hey guys,
I am posting here for the first time, so please be gentle with me :P. I have an assignment of storing a text file in two arrays (one contains both char and int, whereas the other contains just numbers. The text file looks something like this:
Time 2 3 35
Sub 16 85 0 49
Since I am new to programming (not really: Studied structures five years ago), I am having difficulty storing this data into the array. The only thing which I was able to do was to read the data and display it on the screen. Can anyone please help me with the writing part please?
My code looks something like this:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
char myarray[200];
char index=0;
ifstream myfile ("file.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cin>> line;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
Any help would be appreciated.