社区
工具平台和程序库
帖子详情
C++初学者,请教一个简单的问题。
ashy999
2003-11-27 02:34:55
#include<iostream.h>
#include<string.h>
void main()
{
string str("abc");
cout<<str;
}
我在VC++6.0环境下编译时报错,"string"没有声明。可是我看书上就是这末写的。
请高手帮帮忙。
...全文
42
10
打赏
收藏
C++初学者,请教一个简单的问题。
#include #include void main() { string str("abc"); cout<<str; } 我在VC++6.0环境下编译时报错,"string"没有声明。可是我看书上就是这末写的。 请高手帮帮忙。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
10 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
czjcsdn
2003-11-30
打赏
举报
回复
#include<iostream.h>
#include<string>
using std::string;
void main()
{
string s1 = "abc";
cout << s1.c_str() << endl;
//还可以类似这样用
const char *s2;
s2 = "def";
s1 = s1 + s2;
cout<<s1.c_str()<<endl;
}
xstarfox
2003-11-29
打赏
举报
回复
哇~~这个问题也困绕了我好久
今天却突然看到这个帖子,真是多谢拉~~!
minghui000
2003-11-28
打赏
举报
回复
#include <iostream>
#include <string>
using namespace std;
void main()
{
string str("abc");
cout<<str;
}
ashy999
2003-11-28
打赏
举报
回复
明白了,非常感谢诸位高手,以后遇到问题还会向大家请教的,谢谢!
heguobaoceo
2003-11-28
打赏
举报
回复
#include <iostream>
#include <string>
using namespace std;
void main()
{
string str("abc");
cout<<str;
}
这样应该没有问题了啊,因为在库中可以找到的不用.H文件
如果是你自己定义的话应该是“set.h"这样的形式
glacierrr
2003-11-27
打赏
举报
回复
#include <string>
using namespace std;试新版的
#include<iostream.h>
#include<string.h>
已经过时了
SebastianXP
2003-11-27
打赏
举报
回复
using namespace std才是关键啊,建议看看Essential C++ 或是 C++ Primer
ashy999
2003-11-27
打赏
举报
回复
明白了,头文件不加".h"。
ashy999
2003-11-27
打赏
举报
回复
非常感谢psbeond!
我试了一下,还是不行。
E:\程序\VC\piont\piont.cpp(4) : error C2871: 'std' : does not exist or is not a namespace
E:\程序\VC\piont\piont.cpp(9) : error C2065: 'string' : undeclared identifier
Why?
psbeond
2003-11-27
打赏
举报
回复
#include <string>
using namespace std;
或:
#include <string>
...
std::cout<<str;
给
C++
初学者
的忠告
给
C++
初学者
的50个忠告
初学者
C++
学习丰富基础课件
初学者
不错的学习课件,
C++
基本知识,课堂记录等等
易学
C++
完整版付习题答案+源码
易学
C++
习题答案 源码
一位高人对java
初学者
的指点
一位高人对java
初学者
的指点,对初学着应该有用
用
c++
输出
一个
菱形(csdn)————程序.pdf
用
c++
输出
一个
菱形(csdn)————程序
工具平台和程序库
24,854
社区成员
27,330
社区内容
发帖
与我相关
我的任务
工具平台和程序库
C/C++ 工具平台和程序库
复制链接
扫一扫
分享
社区描述
C/C++ 工具平台和程序库
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章