By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,336 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,336 IT Pros & Developers. It's quick & easy.

How do i convert a character array to string.

P: n/a
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

Aug 19 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
> 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

Aug 19 '05 #2

P: n/a
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
Aug 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.