Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Converting a string to lower case.

Posted on 2004-08-30
Medium Priority
Last Modified: 2012-05-05
I am trying to convert a string of data type string to lower case without using a CString variable.  This is because, when I try to run my executable on another machine, it cannot find the MFC dll.

I have tried using tolower and _tolower, but they apparently do not work with strings.  I also tried doing the conversion by moving the string.c_str() value to a constant character * variable, but I only get "zzzz" as the  converted string.

Any other ways of doing this without having to use MFC dll?

Question by:sjlevine34
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 55

Accepted Solution

Jaime Olivares earned 500 total points
ID: 11937318
Traditionally with STL strings:

transform(s.begin(), s.end(), s.begin(), toupper);

Author Comment

ID: 11937568
When I try to compile this, I get the following error:

c:\documents and settings\sjlevine\my documents\my c projects\tigris_mover\lcasestr.cpp(16) : error C2065: 'transform' : undeclared identifier
Error executing cl.exe.

TIGRIS_mover.exe - 1 error(s), 0 warning(s)
LVL 11

Expert Comment

ID: 11937682
maybe you need to

#include <string>
and also


using namespace std;

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 55

Expert Comment

by:Jaime Olivares
ID: 11937972
Sorry, just returning, proper headers has been specified by avizit.

Expert Comment

ID: 11938084
jaime's answer is the right way to do this (except toupper should be tolower) but I don't see why tolower and c_str don't work together, other than using c_str incorrectly.  What might be happening is calling c_str multiple times when it should only be called once, since a call to c_str invalidates the pointer returned by a previous call.  This would make even more sense if your library implementation initializes heap memory to "zzzzzzzz" in debug mode.
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11938268
Sorry about the upper case, not noticed until now. Thank you teratoma.
Maybe STL creators should create some macros or inline functions for this, just like classic strupr and strlwr functions.
That's why I prefer to use standard C strings (char arrays) when not using CString, because I feel I have have full control of what is happening behind the scenes.


Author Comment

ID: 11938576
Sorry I took so long to write this reply after seeing the answers of jaime_olivares and avizit.  I wanted to try the suggestion first, which I did and it did work.  But then I got hung up trying to figure out why my program was no longer working correctly and, after correcting how I build a particular substring and then finally figuring out that I had to reinitialize an fstream before opening a new file (or eof doesn't unset), I finally got things working again.  Needless to say, I got quite a lot of experience using the debugger, which is different from that in Microsoft Visual Basic for Applications, though I think I like it a little better than VBA's.

So, anyway, after dancing around about learning C for 20 years, which included several false starts, I have finally taken the plunge, although I will say the water is quite hot and I now feel thoroughly cooked.

Anyway, really appreciate the help.  Thanks.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question