its exactly what you think it would be..
if the string has 2 letters or more,
then nme and nme, the first 2 letters, need uppercase.
you may want to check for empty strings for the first part too...
if(nme!="CN"||"Cn") //if string begins with CN or Cn
Each condition in an if statement must be independent, you need a condition in the part after the || as well.
But... your if statement doesn't make much sense in the first place.
Perhaps you want to use substring?
The correct syntax and logic would be:
// Example program
bool StartsWith(const std::string& str, const std::string substr)
if (str.length() < substr.length())
return str.substr(0, substr.length()) == substr;
std::string name = "CNabbl";
if (StartsWith(name, "CN") || StartsWith(name, "Cn"))
std::cout << "Starts with CN\n";
std::cout << "Doesn't start with CN\n";
Of course, the above code doesn't actually answer your question of capitalizing the first two letters of the string. You're doing the wrong check. Like jonnin said, if the string has 1 letter, just capitalize the 1st letter, and if the string has more than 1 letter, capitalize the first two letters. Simple.
Also... just a note on variable naming: what is the point of removing the 'a' in "name"? It adds no value to the code, and just makes it harder to read. It's okay to have vowels in variable names :)