Hello everyone. Got a bit of a weird problem here. I cant seem to figure out a way to read a file with a format like this...

hello what 100 200

its a string string integer integer

i need to put each of those values in separate arrays.
eg:
array1[0] = hello;
array2[0] = what;
array3[0] = 100;
array4[0] = 200;

I tried this just as a test to what it will print out but as expected its just flat out reading the file. I am not getting any ideas to differentiate between variables and put them in separate arrays.

ifstream MyData("somefile.txt");
		string data;
		string DataArray[500];
		int i=0;
			while(MyData>>data)
			     {
				cout<<data;
				 DataArray[i] = data;
				 i++;					
			     }
			for(int j=0;j<i;j++)
			     {
				cout<<DataArray[j]<<endl;
			     }

Any suggestions would be very much appreciated. Thanks .

maybe read the variables into a struct and then send them to allocated array

umm....i didnt quite understand that...what i am saying is how to read them individually at all in the first place

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.