Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How do i convert a character array to string.

Reply
Thread Tools

How do i convert a character array to string.

 
 
Venkat
Guest
Posts: n/a
 
      08-19-2005
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



 
Reply With Quote
 
 
 
 
Srini
Guest
Posts: n/a
 
      08-19-2005
> 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());
>


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);

> regards,
> Venkat


Srini

 
Reply With Quote
 
 
 
 
Default User
Guest
Posts: n/a
 
      08-19-2005
Venkat wrote:

> 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());


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


 
Reply With Quote
 
 
 
Reply

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Convert string with control character in caret notation to realcontrol character string. Bart Vandewoestyne C Programming 8 09-25-2012 12:41 PM
Convert an Character to the ASCII Character Code John Gregory Ruby 0 07-05-2009 10:32 PM
Convert native character string to ASCII array of integers Tomás Ó hÉilidhe C Programming 56 03-31-2008 09:13 PM
check and convert lower character to upper character alessio211734@yahoo.it C++ 3 11-18-2007 11:28 AM



Advertisments