Loading array from file using StringStream

First time on this form and new c++ programmer. So I am given a file with an array of numbers, and im trying to use get line and stringstream to get the first line of code to come out on its own and the second line and so on. How would i go about that? Any input would be appreciated.

Array of codes
45 46 89
123 789 523
here is what i have so far:

void loadArray(int a[], int &n)
{
int x;
int y;
int r;
string s="";
string fname = getUserInput("Filename to load from: ");
ifstream infile(fname.c_str());
if (!infile)
errorMsg("File doesn't exist...terminating",true);


while (infile)
{
getline(infile, s);
stringstream ss;
ss.str(s);
ss>>x>>y>>r;

}

infile.close();
}
Last edited on
Hi,
For example >

1
2
3
4
5
6
string data;
ifstream opener;
opener.open("path\\data.txt");
opener >> data;
opener.close();
cout << data << endl;


You could do it simply like that.

It works fine for me

(don't forget to use 'using namespace std;')
Topic archived. No new replies allowed.