I am new to C++. I have a problem regarding access specified elements from a text File. I have two File containg the random sorted integert values. and an Array with some size.
For exapmle if array contain 10 elements and files will contain random number upto 10 with no element in common. such file one contain 1,4,7,8,10 then file 2 will contain rest of the elemnts 2,3,5,6,9.

My problem is how to fetch the specified elements from array and store them either file or an array.

For Example Suppose we have arr[10]= {2,4,7,3,7,8,1,7,3,1};
and file1 have elements 1,4,7,8,10 and File2 have elements 2,3,5,6,9.

so after performing operations my output arrays or text file contain
the corresponding data from array.

such as arr1[]={2,3,1,7,1} and arr2[]={4,7,7,8,3}
we can use text file also for storing these valuse........

please help me out

thanks in Advance....

For Example Suppose we have arr[10]= {2,4,7,3,7,8,1,7,3,1};
and file1 have elements 1,4,7,8,10 and File2 have elements 2,3,5,6,9.

Arrays have a starting index of 0, so you'd have to subtract 1 from these numbers to get the actual index.

Read the numbers from your first file into an int array X, and use X[0],X[1], etc as the index of your arr[10], so arr[X[0]] would be the element corresponding to the first index listed in the first file. Do the same for an array Y read from the second file.

If you're not clear on file handling there are probably dozens of tutorials out there. Here's a good one: http://www.cplusplus.com/doc/tutorial/files/

Thanks........

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.