Hello all,
I want to remove the spaces " " from a specific string.
First I wrote this code:
and it worked then I added an if statement to handle the " " in the z string.Code:#include <iostream> #include <string> using namespace std; int main () { string z=" hello"; string y; for(int x=0;x<z.length();x++) { y=y+z[x]; } cout<<y; system("pause"); }
I added the statement into the for loop.
But the compiler gave me this error!The error was in the new if statement I added.Code:#include <iostream> #include <string> using namespace std; int main () { string z=" hello"; string y; for(int x=0;x<z.length();x++) { if(z[x]!=" ") y=y+z[x]; } cout<<y; system("pause"); }
Can anyone please explain it and tell me how to overcome this problem.error C2446: '!=' : no conversion from 'const char *' to 'int'
There is no context in which this conversion is possible
.\new.cpp(10) : error C2040: '!=' : 'int' differs in levels of indirection from 'const char [2]'
Thank you.



LinkBack URL
About LinkBacks



Thank you all