help string to char

Hi guys, I have written code like

int return_value(char* word){
.
.
.
return some_value;
}

int main(){
string word;
.
cout << return_value(word);
.
}

when I try to debug it give me an error, it says cannot convert to string to char. Please guys help me out here. I would appreciated. Thank you.
so u are saying that breaking up string to character each?
then u can use a char array to store your string.
@bshrestha: Tapai nepali ho? :)

The problem lies in the way you have invoked cout << return_value(word);. word in this case it is a string object, but the function you have defined (int return_value(char* word)) is expecting a character pointer or char*.

What you need to do is define word (inside your main function) as a char array or char[x] (where x is the length of your array).

Another way could be to use the string::c_str() function (see: http://www.cplusplus.com/reference/string/string/c_str/)

Be careful when naming variables, if you have conflicting variable names it may lead confusions regarding which variable you are calling (as I believe this case is here).

Also, next time you post use code tags [ code ]your code[ /code ] (without the spaces), this makes it easier for us to read your code and help you! :D

If you are still confused, post again and I will try clarify it to you.

I hope this helps!
Topic archived. No new replies allowed.