![]() |
| ||
| converting std::string to const chars? Hullo, I need help here I can't get this to work. I'm not sure if the code is correct. Any help would be most appreciated. I basically wanna convert a std::string to a const char array. #include <string> My errors... In function `int main()': I'm using windows xp and Dev-cpp God bless. |
| ||
| Re: converting std::string to const chars? *Sigh* gotta love google. char buf[255]; This works apparently? |
| ||
| Re: converting std::string to const chars? c_str() returns a const char []. bull() takes a char [] as a parameter. That means that any changes made to char[] in bull() should be valid changes in c_str(). However since c_str() returns a const char [] it can't be changed. Therefore the compiler throws an error. Hence, you have to copy c_str() to a char [] before passing it to bull(). You could also try to temporarily ignore the constantness of c_str() when passing it to bull() by using the using the C++ syntax const_cast before the call c_str(). |
| ||
| Re: converting std::string to const chars? Quote:
void bull( const char[] ) |
| ||
| Re: converting std::string to const chars? I know this works, but I don't know if it is a best practise. #include <iostream> OUTPUT: Hello, world! |
| All times are GMT -4. The time now is 6:47 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC