1

how can i make this program to accept both upper and lower case id's. The id when read from file is of upper case.The id's present are in the form of S2345. Help please.

 cout << "Enter client ID TO Change email"; cin >> ids; for(int i=0; i<rec; i++) if(client[i].ID == ids){ cout << "\nEnter New email\n"; cin >> client[i].email; } 
3
  • 1
    I find your question confusing: You ask about how to transform a string, but the code seems to call for a case-insensitive comparison. Both are possible, and usually one doesn't make sense if the other is needed. Which is it? Commented Mar 24, 2015 at 10:00
  • islower and toupper Commented Mar 24, 2015 at 10:01
  • to be precise i dont want the id's to be case sensitive. wen i run this and wen i enter s2345 "s" being in lower case it doesn't accept it. i have to enter S in caps each time. Commented Mar 24, 2015 at 10:05

2 Answers 2

0
#include <boost/algorithm/string.hpp> #include <string> std::string str = "Hello World"; boost::to_upper(str); 
Sign up to request clarification or add additional context in comments.

Comments

0

You can use std::transform() from #include <algorithm> library:

#include <algorithm> // for std::transform #include <functional> // for std::ptr_fun #include <cstring> // for std::toupper int main() { std::string ids; std::cout << "Enter client ID TO Change email"; std::cin >> ids; // make the entire string uppercase std::transform(ids.begin(), ids.end(), ids.begin() , std::ptr_fun<int, int>(std::toupper)); std::cout << ids << '\n'; } 

It may be worth making a function wrapper for it:

std::string to_uppercase(std::string s) { std::transform(s.begin(), s.end(), s.begin() , std::ptr_fun<int, int>(std::toupper)); return s; } 

References: std::transform, std::ptr_fun

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.