i would like to insert my data from txt file to array.
but each line of my txt file contains more than one data.
eg : "Data1","Data2","Data3","Data4"
how do i sepreate each data to array[0][0],array[0][1],array[0][2] and array[0][3]??
i only know how to use getline function to take a whole line of data into an variable.
can sum1 teach me? thanks
chern4ever
0
Light Poster
Recommended Answers
Jump to PostPost some code so that we can see what you have attempted until now.
If you have the same number of values on each line in your file then you can do something like this
ifstream myFile; // declare your data variables; // open your file …
Jump to Posti don get this myFile >> data1 >> data2 >> data3 >> data4;
can u explain in more detail?What don't you get about it? It's the same as:
myFile >> data1; myFile >> data2; myFile >> data3; myFile >> data4;
Jump to PostPerheps while you read the file you can use another stringvariable like:
string Addd1d2; Addd1d2 = data1 + " " + data2;
example of my txt file : hi hi hi hi
data1 will be hi
data2 will be hi
data3 will be hi
data4 will be …
All 10 Replies
stilllearning
148
Posting Whiz
chern4ever
0
Light Poster
VernonDozier
2,218
Posting Expert
Featured Poster
chern4ever
0
Light Poster
chern4ever
0
Light Poster
Liszt
23
Junior Poster
chern4ever
0
Light Poster
stilllearning
148
Posting Whiz
chern4ever
0
Light Poster
VernonDozier
2,218
Posting Expert
Featured Poster
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.