Length of String

When I am using the sizeof(string_name) whatever I input, the value turns to be 4.When I include the string header file, strlen(string_name) is reported undeclared by the compiler.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string a="Manasijmnbmhjt nnnbffhhffdgdfgd";
    string* b;
    b = &a;
    cout<<sizeof(a)<<endl;
    cout<<strlen(a);
    cout<<*b;
    cin.get();
}
Last edited on
sizeof is to determine the size of a structure in memory.
strlen is to determine the length of a C string.
a.length() is the correct way.
Topic archived. No new replies allowed.