string to const char *

  • Thread starter Alan Robert Clark
  • Start date
A

Alan Robert Clark

Hi *

gcc 2.96 RH7.2 refuses this:

string infoFileName = "machineinfo.txt";
ifstream infoFile (infoFileName);

I have recently vowed to move to the standard library stuff, instead of my
usual cobbled together stuff. What am I missing? Surely <fstream> and
<string> should work together?

If I really need to:
ifstream infoFile (infoFileName.c_ptr());
what is the use of using string's as opposed to char* if thats what
everything else expects?

Missing something and Confused. Guidance please.
(newsfeed very unreliable, please Cc: I very often get 3rd generation
replies on the news withou seeing 1st generation replies :-(

Alan

--
Alan Robert Clark, Pr Eng Computational Electromagnetics
Associate Professor Wits University
School of Electrical and Information Engineering
Wits; Gauteng ``Bugs are later known as features''
2050 South Africa Ps 111:10; Ps 37/150
Fax (+27 11)403-1929 (e-mail address removed)(Pref)
Tel (+27 11)717-7223(24hr) <http://YingTongDiddleiPo.ee.wits.ac.za/>
**Linux 2.4pl7(RH7.2)---the choice of a GNU generation.**
 
V

Victor Bazarov

Alan Robert Clark said:
gcc 2.96 RH7.2 refuses this:

string infoFileName = "machineinfo.txt";
ifstream infoFile (infoFileName);

I have recently vowed to move to the standard library stuff, instead of my
usual cobbled together stuff. What am I missing? Surely <fstream> and
<string> should work together?

If I really need to:
ifstream infoFile (infoFileName.c_ptr());

ifstream infoFile (infoFileName.c_str());

, actually.
what is the use of using string's as opposed to char* if thats what
everything else expects?

What "everything else"? The only c-tor in the entire library
that needs const char* instead of const string&, and you call
it "everything"?
Missing something and Confused. Guidance please.

Whatever some functions need you should provide. Why complain?
(newsfeed very unreliable, please Cc: I very often get 3rd generation
replies on the news withou seeing 1st generation replies :-(

Sorry, no e-mails.

Victor
 
J

John Harrison

a...
Hi *

gcc 2.96 RH7.2 refuses this:

string infoFileName = "machineinfo.txt";
ifstream infoFile (infoFileName);

I have recently vowed to move to the standard library stuff, instead of my
usual cobbled together stuff. What am I missing? Surely <fstream> and
<string> should work together?

Maybe they should, but they don't. Its even worse if what you have is
wstring.

If I really need to:
ifstream infoFile (infoFileName.c_ptr());

ifstream infoFile (infoFileName.c_str());
what is the use of using string's as opposed to char* if thats what
everything else expects?

What is 'everything else'? So far you've mentioned ifstream. Most evrything
else works with string. Is having to write .c_str() is such a hardship?

In any case the main point of string is things like automatic memory
handling, not compatibility with iostreams.
Missing something and Confused. Guidance please.
(newsfeed very unreliable, please Cc: I very often get 3rd generation
replies on the news withou seeing 1st generation replies :-(

Alan

john
 

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top