Reading File and printing it on the screen

Hey Guys;
I just saw a strange thing in my codes in reading file from a text file here is codes then I explain where is the strange thing...

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main(){
	char* name;
	int num;
	string s ;
	name = new char[20];
	ifstream fin;
	fin.open("students.dat",ios::in);
	if(!fin.good())
		cout<<"problem\n";
	else
		cout<<"fine";

	fin>>num;     \\first line in the file is number of lines
	cout<<num<<"number of record";

	while(!fin.eof()){
		cout<<"miracle";
		getline(fin,s);
		cout<<s;
       }
	return 0;
}


if i put cin.ignore(); before getline the out put wait for the enter and after entering appear....On the other hand, if i put \n in the end of cout<<"miracle"; half of the things come out....why?


thanks any one if explain what's happening when file is reading and the enter and cin.ingnore() what are doing over there?!....

cheers
Topic archived. No new replies allowed.