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 PostIf you use a variable of the type ifstream to read your data like I suggested, it will use a space as a separator for each variable.
If you want your variables to store list of words and not just one word, then you will need to read in …
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.