简单使用c ++ string length()函数不编译

Nnp*_*Nnp -3 c++ eclipse string

我在Eclipse中用c ++做了一个非常基本的std :: string用法,并且无法弄清楚为什么它不起作用.

示例代码:

std::string str = "hello";
cout << str << ":" str.length();
Run Code Online (Sandbox Code Playgroud)

代码未编译时出现以下错误: Method 'length' could not be resolved

为什么?

Dav*_*e S 7

你错过了一个'<<'

cout << str << ":" << str.length();