Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 19th, 2005, 10: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, 10: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, 05: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

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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 network members.
Post your question now . . .
It's fast and it's free

Popular Articles