Newbie: how do I convert basic_string to char*? 
Author Message
 Newbie: how do I convert basic_string to char*?

I have a Win32 Console Application project where I read in a file, find and
replace some strings, and either write to file or transmit the string via a
socket.

I've puzzled it all together except the socket bit. By looking at some
examples I've drawn the conclusion that I must convert this string. So, how
do I convert the basic_string I've used to char*?

Thanx,
Fred



Tue, 30 Jul 2002 03:00:00 GMT  
 Newbie: how do I convert basic_string to char*?


Quote:
> I have a Win32 Console Application project where I read in a file,
find and
> replace some strings, and either write to file or transmit the string
via a
> socket.

> I've puzzled it all together except the socket bit. By looking at some
> examples I've drawn the conclusion that I must convert this string.
So, how
> do I convert the basic_string I've used to char*?

Uhmmm... basic_string::c_str()?

Newbie or not, you REALLY need to learn the documentation.  If you'd
spent 30 seconds looking at the documentation for basic_string you
wouldn't have needed to ask this question.

--
William E. Kempf
Software Engineer, MS Windows Programmer

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 30 Jul 2002 03:00:00 GMT  
 Newbie: how do I convert basic_string to char*?
    First of all, you should be using basic_string directly.  Use string or
wstring instead (they are typedefs of basic_string).

    Second, to get a const char* to the data of a string, use the c_str()
member variable:

    void func(const char*);

    string HW("Hello, World!");
    func( HW.c_str());

--
Truth,
James Curran
http://www.NJTheater.com
http://www.NJTheater.com/JamesCurran


Quote:
> I have a Win32 Console Application project where I read in a file, find
and
> replace some strings, and either write to file or transmit the string via
a
> socket.

> I've puzzled it all together except the socket bit. By looking at some
> examples I've drawn the conclusion that I must convert this string. So,
how
> do I convert the basic_string I've used to char*?

> Thanx,
> Fred



Tue, 30 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Newbie: Can not convert for char to unsigned char

2. Converting char array of literals chars to escape chars

3. Newbie: Howto convert char variable __gc into CString?

4. convert 2 chars to 1 int (newbie)

5. newbie - convert a float to char*

6. Newbie: convert char* to int

7. newbie - Convert from long to char

8. newbie Help: Converting CString and char

9. basic_string<char> as a base class

10. Parsing in basic_string<char> or string

11. help me understand basic_string<char>::replace...

12. Converting float to a basic_string...

 

 
Powered by phpBB® Forum Software