求救!有关c++问题(菜鸟问题)

mrjrabbit 2003-08-08 11:43:50
各位大哥帮忙看看
#include <iostream.h>
#include <string.h>
using namespace std;
void main()
{
string str= "999";
cout<<str;
}

怎么会提示没有定义string、using声明错误这两个错误呢,
...全文
30 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jack_wq 2003-08-11
  • 打赏
  • 举报
回复
问GZCompiler(编译器) ( )一个问题:不是说C++标准中关于头文件的引用可以省略.h吗?这样string 和 string.h 难道不是一个文件?
dddd8888 2003-08-11
  • 打赏
  • 举报
回复
#include <iostream.h>
#include <string.h>

这两个文件也能达到你上面的目的,所以程序通过
不过它和 <iostream> 和 〈string>
含义不同
tybgk 2003-08-08
  • 打赏
  • 举报
回复
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str= "999";
cout<<str;
return 0;
}
jjchzh 2003-08-08
  • 打赏
  • 举报
回复
#include <iostream>
#include <string>
using namespace std;
void main()
{
string str= "999";
cout<<str;
}
GZCompiler 2003-08-08
  • 打赏
  • 举报
回复
#include <iostream>
#include <string>
using namespace std;

注意 string 和 string.h 绝对不是一个文件,不能混淆!
hackingtruth 2003-08-08
  • 打赏
  • 举报
回复
采取下面方法中和一种:
一、
#include <iostream>
#include <string>
using namespace std;
void main()
{
string str= "999";
cout<<str;
}
二、
#include <iostream.h>
#include <string.h>

void main()
{
string str= "999";
cout<<str;
}

三、
#include <iostream>
#include <string>

void main()
{
string str= "999";
std::cout<<str;
}

其实还有一种方法,就是在引入名字空间的时候只引入你需要的那一部分,比方说在本例中只需要引入cout就可以了

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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