Iam trying to read a text file containing integers into an integer array. If the Input is: 1 3 4 5 6 (with space in between) It is working fine.
but if the input is: 1,3,4,5,6 (comma separated) .Its just printing 1.(first digit).If the program finds 1,3,4,5,6 as a single entity then it should print 1,3,4,5,6 as the first index ryt? And also File>>x , does this expression take value one by one by detecting the space in between??
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
int n = 0; //n is the number of the integers in the file ==> 12
int num;
int arr[100];
int x;
int sum = 0;
ifstream File;
File.open("integer.txt");
if(!File.is_open())
{
cout<<"It failed"<<endl;
return 0;
}
while(File>>x)
{
arr[n] = x;
n++;
}
File.close();
cout<<"n : "<<n<<endl;
for(int i=0;i<n;i++)
{
cout << arr[i] << " ";
}
return 0;
}