sjlevine34
asked on
Converting a string to lower case.
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?
sjl
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?
sjl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
maybe you need to
#include <string>
and also
#include<algorithm>
using namespace std;
#include <string>
and also
#include<algorithm>
using namespace std;
Sorry, just returning, proper headers has been specified by avizit.
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.
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.
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.
ASKER
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.
sjl
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.
sjl
ASKER
Compiling...
lcasestr.cpp
c:\documents and settings\sjlevine\my documents\my c projects\tigris_mover\lcas
Error executing cl.exe.
TIGRIS_mover.exe - 1 error(s), 0 warning(s)