lundi 28 avril 2014

Why can't execute 'ifstream' in this state


Vote count:

0





#include <iostream>
#include <fstream>

using namespace std;

int main() {
int a;
char b;
ifstream in("a.txt");

if (!(in >> a))
in >> b;
if (!(in >> a))
in >> b;
in >> b;
in >> b;

cout << a;
cout << b;
}//source code

5 a b c d e
//a.txt



  1. If there is a int in the file I want to read it as int and

  2. If there is a char in the file I want to read it as char.

  3. why can't read 'char b' after try to read b as int?



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire