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 . . .