注册 登录
编程论坛 C++教室

c++ primer 的错误

hu289363109 发布于 2008-11-16 22:19, 751 次点击
今天看c++primer
书上第26页写到:

#include <iostream.h>
#include <string>
int main()
{
    string word;
    while(cin>>word)
        cout>>"word read is:">>word>>'\n';
    cout>>"ok:no more words to read:bye!\n";
    
    return 0;
}

可是明显有低级错误嘛.

我觉得应该是


#include <iostream.h>
#include <string>
int main()
{
    string word;
    while(cin>>word)
        cout<<"word read is:"<<word<<'\n';
    cout<<"ok:no more words to read:bye!\n";
    
    return 0;
}

[[it] 本帖最后由 hu289363109 于 2008-11-16 22:22 编辑 [/it]]
2 回复
#2
mayuebo2008-11-17 10:38
应该是cout<<
另一个引用string 好像要using namespace std;
这个可能是翻译时没有注意,原版应该没有这个问题吧。
#3
为爱西行2008-11-17 16:38
是“\n”吧,cout后面也应该是<<。
1