By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,132 Members | 1,948 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,132 IT Pros & Developers. It's quick & easy.

string to const char *

P: n/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?

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 cl***@YingTongDiddleIPo.ee.wits.ac.za(Pref)
Tel (+27 11)717-7223(24hr) <http://YingTongDiddleiPo.ee.wits.ac.za/>
**Linux 2.4pl7(RH7.2)---the choice of a GNU generation.**

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Alan Robert Clark" <cl***@YingTongDiddleiPo.ee.wits.ac.za> wrote...
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
Jul 19 '05 #2

P: n/a

"Alan Robert Clark" <cl***@YingTongDiddleiPo.ee.wits.ac.za> wrote in message
news:Pi**************************************@Ying TongDiddleiPo.ee.wits.ac.z
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
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.