Is it bossible to pass string as param to this func?

Started by
7 comments, last by Craazer 21 years ago
Hi, if I have string can I anyway pass it to that function below? I tryed using c_str() but obiously that doesn''t work.
  
void Cout(char* str)
{
 cout<<str;
}
  
Please don''t say use char, the problems this.
Advertisement
How about:
void Cout(const char *str) {   cout << str; }   
"after many years of singularity, i'm still searching on the event horizon"
quote:Original post by DerekSaw
How about:
void Cout(const char *str) {   cout << str; }    


Ah! so simble (what was I thinking?) Thanks man!
or better yet
Cout((char*)string.c_str());
quote:
or better yet
Cout((char*)string.c_str());


How''s that better?
quote:or better yet
Cout((char*)string.c_str());


don''t try this at home
quote:Original post by Craazer
Ah! so simble (what was I thinking?) Thanks man!


Is the 'P' letter missing in your keyboard?
And for your question, yes you can.

[edited by - xaxa on March 25, 2003 4:24:50 AM]
[size="2"]I like the Walrus best.
quote:Original post by Anonymous Poster
or better yet
Cout((char*)string.c_str());


c_str() already returns a char*, why would you want to cast it?
no, it returns a const "char*". don''t cast the const away unless you really have to and know it is safe in the expression you use it.

This topic is closed to new replies.

Advertisement