I want to see if the value of a string equals a certain text. But I can't make it. There are two problems :
1) It seems 'tolower' doesn't work with strings. What to use then?
2) When I delete tolower, it works, but I have an output of "You didn't enter 'add'" even when I do enter 'add'. What's the problem? Is it due to the null byte? What to change?
If you actually used strings, comparison would work:
(also, you can drop the stuff that visual studio adds, although if you drop stdafx.h, you need to untick 'use precompiled headers' in project settings)
#include "stdafx.h" //create a new "Blank" project and paste the new code in
#include <stdio.h>#include <math.h>#include <string.h>
#include <algorithm>usingnamespace std;
int _tmain(int argc, _TCHAR* argv) //This was added automatically by Visual Studio. No idea what it does.
cout<<"Please Enter 'add'"<<endl;
if (tolower(input)=="add")transform(input.begin(), input.end(), input.begin(), ::tolower);
if(input == "add")
cout<<"You entered 'add'" <<endl;
}else cout<<"You didn't enter 'add'"<<endl;