cin,cout 编译错误

idot 2008-03-12 09:29:57
我在vc2005下新建空白工程,在工程下新建代码文件,输入代码如下:
//============================================================================
// Name : covertString.cpp
// Author : wangxiwei
// Version :
// Copyright : skcc
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
string inputed;
cin >> inputed;

if( inputed.length() == 0) {
cout << "can not reverse empty string !" << endl;
}
else{
string converted ;
size_t wordStartPos = inputed.rfind(" ",0,inputed.length());
size_t wordEndPos = string::npos;
while ( wordStartPos >= 0){
converted += inputed.substr(wordStartPos,wordEndPos);
cout << converted << endl;
wordStartPos = inputed.rfind(" ",0,wordStartPos);
}
}
return 0;
}
在cin,cout处编译出错,提示c2679错误。为什么?
...全文
109 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
idot 2008-03-12
  • 打赏
  • 举报
回复
多谢大家的参与。
feiniao619 2008-03-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 akirya 的回复:]
有些标准库在包含iostream的时候会将string这个头文件包含进来。
所以不需要另外包含,最好还是写上#include <string> 才对
[/Quote]

你太有才了..
jianyuanPC 2008-03-12
  • 打赏
  • 举报
回复
#include <iostream>
#include<string>//string全为小写
using namespace std;

int main() {
string inputed;
cin >> inputed;

if( inputed.length() == 0) {
cout << "can not reverse empty string !" << endl;
}
else{
string converted ;
size_t wordStartPos = inputed.rfind(" ",0,inputed.length());
size_t wordEndPos = string::npos;
while ( wordStartPos >= 0){
converted += inputed.substr(wordStartPos,wordEndPos);
cout << converted << endl;
wordStartPos = inputed.rfind(" ",0,wordStartPos);
}
}
return 0;
}
  • 打赏
  • 举报
回复
有些标准库在包含iostream的时候会将string这个头文件包含进来。
所以不需要另外包含,最好还是写上#include<string>才对
Treazy 2008-03-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 idot 的回复:]
akirya,按你的方法已解决;
但是在没有 include <string> 的情况下,在minGW + eclipse下编译却能通过,如何解释?
[/Quote]

不同的编译器,工程头文件可能已经包含了部分头文件!
idot 2008-03-12
  • 打赏
  • 举报
回复
akirya,按你的方法已解决;
但是在没有 include <string>的情况下,在minGW + eclipse下编译却能通过,如何解释?
Treazy 2008-03-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 akirya 的回复:]
还需要include <string>
[/Quote]
  • 打赏
  • 举报
回复
还需要include<string>

33,321

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧