help me out

closed account (EwCiz8AR)
why this program not working with string data type when i use char data type instead of string so this program run easily but not with string???

1
2
3
4
5
6
7
  #include<iostream.h>
#include<string>
using namespace std;
main(){
string a;
cin>>a;
cout<<stlwr(string a);}
Last edited on
Maybe you should use

cout<<strlwr(a);

?
closed account (EwCiz8AR)
yep i try this but not working:(
Last edited on
strlwr requires you to use char* not string I think.
The Reason it doesn't work is because strlwr is originally a C function (and a non standard), and C doesn't know/have a std::string type; (class) therefore it doesn't have a implementation for it

There are also some issues w/ your code :
<iostream.h> must be <iostream> main must be int main()
remove string in line 7, we don't need to include the type when passing arguments

Consider using this function instead ( for std::string )
1
2
3
4
5
6
7
8
std::string strlwr ( std::string& str )
{
    std::string temp( str );
    for( auto& i : temp )
        i = tolower( i );
    
    return temp;
}

note compile it w/ -std=c++11

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

std::string strlwr ( std::string& str )
{
    std::string temp( str );
    for( auto& i : temp )
        i = tolower( i );
    
    return temp;
}

int main()
{
    std::string str( "HELLO" );
    std::cout << strlwr( str );
}


remove the std:: prefixes if you have using namespace std;
Last edited on
Topic archived. No new replies allowed.