473,239 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,239 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 10883
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
26
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i don´t have a lot of success. Can anybody help me (and understand my english :-))? I have a...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
13
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
18
by: Toto | last post by:
Hello, my problem is quite simple to explain. I have the following string: "table+camera" and I want to remove the + sign: "tablecamera". How do i do that ?
35
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
35
by: jacob navia | last post by:
Hi guys! I like C because is fun. So, I wrote this function for the lcc-win32 standard library: strrepl. I thought that with so many "C heads" around, maybe we could improve it in a...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.