Iostream : Déclaration globale impossible ?
A ma grande surprise je me rends compte que ce code ne compile pas car iostream est déclaré dans la fonction main() et que j'en appel les paramètres dans ma fonction "void bloc()".
Comment je dois m'y prend dans un tel cas pour pouvoir manipuler le fichier avec une portée globale ?
A savoir que si je déclare ifstream avant "main()", je perds argv[1].
Je ne dois quand même pas pointer partout ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <cstdlib>
#include <iostream>
#include <fstream>
void bloc();
using namespace std;
int main(int argc, char *argv[])
{
ifstream fichierEntree (argv[1], ios::binary);
if (fichierEntree.is_open())
{
bloc();
fichierEntree.close();
}
else
{
cout << "Fichier introuvable !" << endl;
}
system("pause");
return 0;
}
void bloc()
{
float flottant = 0;
fichierEntree.read(reinterpret_cast<char*> (&flottant), 4);
cout << flottant << endl;
} |