+ 1

How to ignore capital and small letter in if statement in cpp program?

When I use if statement in cpp program, there comes a issue of capital and small letter. When I type my name there in small letter and I had stated in program my name in capitle letter ,it does not runs. So can any body can suggest me to avoid this. This is my code : #include <iostream> #include <string> using namespace std; int main() { string name: cout<<"Enter your name "<<endl; getline(cin, name); if (name=="Name") { cout<<"Correct"<<endl; } return 0; } This is just example but I have to use this type of format at another program.

13th Jun 2019, 5:04 AM
Aman Kumar
Aman Kumar - avatar
3 odpowiedzi
+ 2
Thank you so much. It helped a lot.
14th Jun 2019, 4:50 AM
Aman Kumar
Aman Kumar - avatar
+ 2
And what to do if i have to change capitle and small letters word
14th Jun 2019, 7:13 AM
Aman Kumar
Aman Kumar - avatar
+ 1
#include <iostream> using namespace std; int main(){ string name; cout << "Enter your name "<< endl; getline(cin, name); if(name[0] <= 'Z'){ //check if upper name[0] += 32; //make upper } cout << name << endl; return 0; } This will take the first letter and make it lowercase each time. The way this works is that all letters are stored as numbers, and lowercase letters are 32 higher than uppercase. This code will simply add that 32 (this can cause errors with special characters though, so be careful.)
13th Jun 2019, 5:37 AM
Jackson O’Donnell