: : : #include <fstream>
: : : #include <iostream>
: : : using namespace std;
: : : int main()
: : : {
: : : ifstream infile("input.dat");
: : : float temp;
: : :
: : : infile >> temp; // Assuming "input.dat" exists
: : :
: : : for(int i=0;i<=2;i++)
: : : {
: : : cout << "\n Number in file input.dat = " << temp;
: :
//u r not taking input further from the file
: : : }
: : :
: : : return 0;
: : : }
: :
: : the code should be like this:
: :
: : int main()
: : {
: : ifstream infile("infile.dat");
: : float temp;
: :
: : while(infile >> temp)
: : cout << temp << endl;
: :
: : return 0;
: : }
: :
: :
:
:
: Oh, the first code was the real one? Yes, it is missing a loop. You are only reading one value from the file. Regarding newline and other whitespaces, ifstream should sort them away for you. Or you can use getline() if you prefer that.
:
:
I am sorry, In hurry I have just missed that loop, but I mean to say the same as you said. Problem is of newline charactor.