OVH Cloud OVH Cloud

Methode open

3 réponses
Avatar
Pascal
Bonjour,

Je fais:
string nomFic;
ifstream fic;

fic.open(nomFic)

Et g++ me sort une erreur. Ca marche si je mets
fic.open("machin");
ou
fic.open(char *);

Comment faire?

3 réponses

Avatar
fabrizio
fic.open(nomFic.c_str())

non ?
Avatar
xavier
Pascal a dit le 07/02/2005 14:55:
Bonjour,

Je fais:
string nomFic;
ifstream fic;

fic.open(nomFic)

Et g++ me sort une erreur.

Comment faire?


fic.open(nomFic.c_str());

xavier

Avatar
Fabien LE LEZ
On Mon, 07 Feb 2005 14:55:07 +0100, Pascal :

Je fais:
string nomFic;
ifstream fic;

fic.open(nomFic)

Et g++ me sort une erreur.


Oui, c'est encore une bizarrerie du C++.

Comment faire?


Tout simplement utiliser la fonction membre c_str() de std::string :

fic.open(nomFic.c_str())

--
;-)