初级字符串问题

herogyf 2003-10-04 05:05:41
#include <string.h>
#include <iostream.h>
main()
{
string str("this is a tesr!!");
cout<<str<<endl;
}


出现:undifined symbol 'string'
statement missing ;
undefined symbol 'str'的出错提示,该如何解决???
...全文
18 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wolf0403 2003-10-06
  • 打赏
  • 举报
回复
TC3 似乎是不支持模板的吧。。。
楼上星星忘记 std:: 了^_^
lemon520 2003-10-05
  • 打赏
  • 举报
回复
换个编译器吧!
如果连string都不支持的话!
tuxw 2003-10-05
  • 打赏
  • 举报
回复
TC3要用strng.h,不过那个string类很简单
herogyf 2003-10-04
  • 打赏
  • 举报
回复
还是不行呀,我用的是tc3.0
RookieStar 2003-10-04
  • 打赏
  • 举报
回复
两个大问题:
1.<string.h>包括的c-style字符串的处理函数,如strcpy,strcmp,strcat等,<string>才是真正的头文件。

2.用<string>就要用<iostream>进行流操作,不要再用老的<iostream.h>

PS:STL的头文件都不带.h的,记住了以后就不会再犯类似的错误了。
  • 打赏
  • 举报
回复
string类型位于string中,而不是string.h中,后者包含了很多操作char*字符串的函数
#include <string>
#include <iostream.h>
main()
{
string str("this is a tesr!!");
cout<<str<<endl;
}
tuxw 2003-10-04
  • 打赏
  • 举报
回复
string 并未包含在string.h中,string.h只是一个老的C库,改成下面的形式就可以了

#include <string>
#include <iostream>
using namespace std;

void main()
{
string str("this is a tesr!!");
cout<<str<<endl;
}

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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