Hi I want to create a program where I will input different names and I will output it in UPPERCASE FORM. However there's a bug in my code, can you help me to figure it out?
It said "[Error] no match for 'operator>=' (operand types are 'std::string {aka std::basic_string}' and 'int')"
int times;
string name [1000];
int i = 1;
int hold = 0;
int j ;
int cont;
while( i != 0){
cout<<"Enter Name "<<endl;
cin>>name[hold];
times = hold;
for ( j = 0 ; j <= strlen(name) ; j++){
if (name[j] >= 97 && name[j] <= 122){
name[j] = name[j] -32;
}
}
cout<<"\n[1] for Add"<<endl;
cout<<"[2] for Stop"<<endl;
cin>>cont;
if ( cont == 1){
hold++;
i = 1;
}else{
i = 0;
}
}
for ( i = 0 ; i <= times ; i++){
cout<<name[i]<<"\n";
}
You should pass a const char*
to the strlen() function. Refer: https://www.programiz.com/cpp-programming/library-function/cstring/strlen
But the 'name' is an string type array. Therefore the compiler returns an error.
Also the data type of name[j] is std::string. Therefore you cannot compare name[j] with an integer.
If you need to convert a string to uppercase string, please use the below code block (str is a string variable).
std::transform(uppers.begin(), uppers.end(), uppers.begin(), [](unsigned char c){ return std::toupper(c); });