tolower() problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "stdafx.h"
#include <algorithm>

#include <iostream>
#include <string>
int main(){
	std::cout << "Are you OK?";
	std::string a;
	std::cin >> a;
	tolower(a);
	
	
	if (a == "Yes")
		std::cout << ".";
	else if (a == "NO")
		std::cout << "..";
	
	
}

tolower(a); is not working Error no suitable conversion from std::string to int exists. Help.
Last edited on
tolower() operates on a single character at a time. Also it leaves the parameter unchanged, you need to make use of the value returned by the function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <algorithm>
#include <iostream>
#include <string>

int main()
{
    std::string a = "Hello World";
    
    for (char & ch : a)
        ch = tolower(ch);
    
    std::cout << a << '\n';
    
    std::transform(a.begin(), a.end(), a.begin(), toupper);
    std::cout << a << '\n'; 

}
hello world
HELLO WORLD


http://www.cplusplus.com/reference/cctype/tolower/
http://www.cplusplus.com/reference/algorithm/transform/
Last edited on
Topic archived. No new replies allowed.