vendredi 27 mai 2016

strlen() in C++ not working with string variable on code Block

#include <iostream>
#include <string>
#include <cstring>


using namespace std;

int main()
{
    string b="hello";

    cout<<b;

    int c = strlen(b);

    cout << "Hello world!" <<c<< endl;
    return 0;
}

When I try to run this I get the error below

||=== Build: Debug in strlen (compiler: GNU GCC Compiler) ===| C:\Users\Waters\Desktop\hellow world\strlen\main.cpp||In function 'int main()':| C:\Users\Waters\Desktop\hellow world\strlen\main.cpp|14|error: cannot convert 'std::string {aka std::basic_string}' to 'const char*' for argument '1' to 'size_t strlen(const char*)'| ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Aucun commentaire:

Enregistrer un commentaire