Connecting Tech Pros Worldwide Forums | Help | Site Map

How do i convert a character array to string.

Venkat
Guest
 
Posts: n/a
#1: Aug 19 '05
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




Srini
Guest
 
Posts: n/a
#2: Aug 19 '05

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

Default User
Guest
 
Posts: n/a
#3: Aug 19 '05

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


Closed Thread