Connecting Tech Pros Worldwide Help | Site Map

How do i convert a character array to string.

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 19th, 2005, 09:45 AM
Venkat
Guest
 
Posts: n/a
Default How do i convert a character array to string.

Hi All,

Can someone tell me how do we convert a character array to string.
I know the other way.

For eg:-
String strvar = "hello";
printf("%s",strvar.c_str());

regards,
Venkat




  #2  
Old August 19th, 2005, 09:55 AM
Srini
Guest
 
Posts: n/a
Default Re: How do i convert a character array to string.

> Hi All,[color=blue]
>
> Can someone tell me how do we convert a character array to string.
> I know the other way.
>
> For eg:-
> String strvar = "hello";
> printf("%s",strvar.c_str());
>[/color]

I hope you meant, string(lowercase 's'). And what are you doing in the
first statement? Converting a array of chars to a string object.

char arr[] = "Hello";
std::string str(arr);
[color=blue]
> regards,
> Venkat[/color]

Srini

  #3  
Old August 19th, 2005, 04:55 PM
Default User
Guest
 
Posts: n/a
Default Re: How do i convert a character array to string.

Venkat wrote:
[color=blue]
> Hi All,
>
> Can someone tell me how do we convert a character array to string.
> I know the other way.
>
> For eg:-
> String strvar = "hello";
> printf("%s",strvar.c_str());[/color]

I assume the "String" with the uppercase S is a typo, and you really
mean std::string. std::string has both a constructor and an assignment
operator that char* arguments.


std::string s("hello");

std::string s;

s = "hello";



You need to get a decent reference book that covers these things. This
is basic stuff.




Brian


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.