I m surprised and wanna know that how the compiler understand the sequence of how data was entered. as i didnt use any space any tab not a new line, how it can point to the original value from a
single line..?????????

find.txt contain the following line with out spaces with out tabs with out new line.

find.txt
123433344566786804321235667

Below is the C++ code.

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	int arr[10];
	ofstream out;
	 /////////////////////////////////////////// Use for writing array of integer in file
	out.open("find.txt",ios::out);
	for(int i =0;i<10;i++){
		cout << "Enter Number for Input in file ";
		cin >> arr[i];
		out << arr[i];
	}
	out.close();
	
	cout << "------------------------------File contents------------------------------" << endl;
	ifstream in;
	in.open("find.txt",ios::in);
	int count=0;

	while(in.eof()==0){
		in >> arr[count++];
	}

	for(int i =0;i<10;i++){
		cout << "Data: " << arr[i] << endl;
	}

	in.close();
	return 0;
}

output of the program:

Enter Number for Input in file 123
Enter Number for Input in file 4333
Enter Number for Input in file 44
Enter Number for Input in file 5
Enter Number for Input in file 6678
Enter Number for Input in file 680
Enter Number for Input in file 432
Enter Number for Input in file 1
Enter Number for Input in file 23
Enter Number for Input in file 5667
------------------------------File contents------------------------------
Data: 123
Data: 4333
Data: 44
Data: 5
Data: 6678
Data: 680
Data: 432
Data: 1
Data: 23
Data: 5667
Press any key to continue . . .

I m surprised and wanna know that how the compiler understand the sequence of how data was entered. as i didnt use any space any tab not a new line, how it can point to the original value from a
single line..?????????

The compiler has no clue how to interpret those digits. The only way it will work is if you write a space, tab, or some other character that acts as a separator.

It only appears to work -- that read loop didn't actually do anything because there was probably an integer overflow error on the first read. What you saw on the screen was the old data left in the array after keyboard input.

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.