471,612 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,612 software developers and data experts.

string to const char *

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
2 10793
"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

"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.

Similar topics

2 posts views Thread by Andrew | last post: by
26 posts views Thread by Kai Jaensch | last post: by
7 posts views Thread by al | last post: by
4 posts views Thread by songkv | last post: by
18 posts views Thread by Toto | last post: by
35 posts views Thread by michael.casey | last post: by
35 posts views Thread by jacob navia | last post: by
1 post views Thread by XIAOLAOHU | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.