Thursday, July 9, 2009

What is wrong with my C++ Program?

#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;





using namespace std;





int main(int argc, char *argv[])


{ string sentence;


cin %26gt;%26gt; sentence;


if (sentence[0] == "h") {


sentence[0] = "r";


}


if (sentence[1] == "e") {


sentence[1] = "u";


}


system("PAUSE");


return EXIT_SUCCESS;


}


I wrote this program to transform written text into code but I don't know what's wrong with it. Obviously, this is only for 2 letters... Every time i get these errors...


Line 12, ISO C++ forbids comparison between pointer and integer.


Line 10, Invalid conversion from `const char*' to `char'.

What is wrong with my C++ Program?
It looks like you are comparing a char with a string





sentence[0] is a char "h" is a string.








try comparing it with the character. 'h' in single quotes, not double.. "h" is a string, 'h' is a char.





if(sentence[0] == 'h')


No comments:

Post a Comment