You may use the wrong printf. You can use std::cout to output the para2 but not use printf for the string type. As printf can only print out original type like int, double, float, ulong, char, char* etc.
#include <iostream>
#include <string>
int main(int argc, char* argv[])
{
std::string para2="";
if(argc==2 && argv[1]!=NULL)
{
para2 = std::string(argv[1]);
std::cout<<para2<<std::endl;
}
return 0;
}
You can refer to "printf" on strings prints gibberish and "printf" on strings prints gibberish.
If you want to find the specified string in char*, you can use strstr() function to do such things. And string::find can also do the find work, you can refer to http://www.cplusplus.com/reference/string/string/find/
For string::find function, the return value is size_t type. And the return value returns the position of the first character of the first match. If no matches were found, the function returns string::npos.
You should always use string::npos for the check condition but not with 0.