Name salary Department john 12000 IT jack 14000 sales
#include <iostream.h> #include <conio.h> #include <fstream.h> #include <stdlib.h> void main() { clrscr(); char name[50]; int sal; // this creates problem char dept[30]; ifstream infile; infile.open("bca.txt"); while(!infile.eof()) { infile>>name>>sal>>dept; cout<<name<<" "<<sal<<" "<<dept<<endl; } infile.close(); getch(); }
atoi()
// skip the head line infile>>name>>name>>name; while(!infile.eof()) { // read the record infile>>name>>sal>>dept; // drop if read the line fails if(infile.rdstate()) break; // display the readen data cout<<name<<" "<<sal<<" "<<dept<<endl; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)