pushkar
Journeyman
I have to read a text file using ifstream. The file contents are
I have written following two codes for reading the file
code 1
code 2
The second code is working, but the first one isn't giving the desired output. In the first code, the third line, which is the string, isn't giving proper output.
I cannot use the second code, because I have to store everything except the third line in int or float types, while in the second code, i am storing everything in strings.
Please advise me what is the problem.
BY THE WAY, I AM USING TURBO C++ 3.0. Can this be causing any problem?
Code:
1
10
Insurgence
1998
7.1
0
I have written following two codes for reading the file
code 1
Code:
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
char c[100];
ifstream fin("MOVIE.DOC");
int n;float m;
fin>>n;
cout<<n<<endl;
fin>>n;
cout<<n<<endl;
fin.getline(c, 100, '\n');
cout<<c;
cout<<endl;
fin>>n;
cout<<n<<endl;
fin>>m;
cout<<m<<endl;
fin>>n;
cout<<n<<endl;
getch();
}
code 2
Code:
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
ifstream fin("MOVIE.DOC");
char c[100];
while(!fin.eof())
{
fin.getline(c,100,'\n');
cout<<c<<endl;
}
getch();
}
The second code is working, but the first one isn't giving the desired output. In the first code, the third line, which is the string, isn't giving proper output.
I cannot use the second code, because I have to store everything except the third line in int or float types, while in the second code, i am storing everything in strings.
Please advise me what is the problem.
BY THE WAY, I AM USING TURBO C++ 3.0. Can this be causing any problem?