-4

I'm doing a very basic usage of std::string in c++ in Eclipse, and can't figure out why it's not working.

The sample code:

std::string str = "hello";
cout << str << ":" str.length();

The code is not compiling with the following error: Method 'length' could not be resolved

Why?

4

2 回答 2

7

你错过了一个'<<'

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

于 2013-01-18T14:04:30.163 回答
0

确保 #include 在文件顶部。但是,我认为如果你不这样做,你会收到一个关于无法解析 std::string 的错误。

于 2013-01-18T16:00:28.467 回答