cb里面是不是没有#include<string>
codeblocks吧
全部回复
仅看楼主
level 8
七夜7七 楼主
cb里面是不是没有#include<string>,好像编译时出了点错!!
2013年04月12日 08点04分 1
level 11
与cb无关啊,<string>是标准C++库
2013年04月13日 01点04分 2
level 8
七夜7七 楼主
你说对了!![汗]
2013年04月13日 04点04分 3
level 11
<string.h>才是吧。。。
2013年04月14日 08点04分 4
他说的是C++
2013年04月14日 08点04分
回复 静听花亦落 :就是c++啊。。C可没有string,只有stdio,stdlib.....
2013年04月14日 08点04分
回复 LOMON_first :只知道在C语言里应该用
#include <string.h>,在C++里,可以写#
include 或
#include <cstring> 或者直接 #
include
2013年04月14日 10点04分
用#include<string>,这回我明白了。。。
2013年04月14日 10点04分
level 8
七夜7七 楼主
用#include就行了。看下面的程序吧!!
/**************************************************************************
字符串类的操作(string):( #include )
--------------------------------------------------------------------------
运算符 示例 注释
--------------------------------------------------------------------------
= s1 = s2 用s2给s1赋值
+ s1 + s2 用s1和s2连接成一个新串
+= s1 += s2 等价于s1=s1+s2
== s1 == s2 判断
!= s1 != s2 判断
< s1 < s2 判断
<= s1 <= s2 判断
> s1 > s2 判断
>= s1 >= s2 判断
[] s1[i] 访问串对象s1中下标为i的字符
>> cin >> s1 从键盘输入一个字符串给串对象s1
<< cout << s1 将串对象s1输出
--------------------------------------------------------------------------
**************************************************************************/

#include <iostream>#
include
using namespace std;
int main()
{
string str1 = "ABCD"; ///定义string类对象并初始化
string str2 = "123"; ///对str2初始化
string str3("123"); ///对str3初始化
string str4,str5;
cout << str1 << endl;
cout << str2 << endl;
cout << str3 << endl;
cout << str1+str2 << endl; ///对运算符 + 的使用
cout << endl;
str4 = str1+str2; ///对运算符 + 的使用
cout << str4 << endl;
str1 += str2;
cout << str1 << endl;
str1 = str2;
cout << str1 << endl;
cout << endl;
if(str1!=str2) ///字符串的判断
cout << "str1!=str2" << endl;
else
cout << "str1<>str2" << endl;
cout << endl;
cout << "请输入一个字符串给str5:" << endl; cin >> str5; ///输入时遇到空格结束
cout << "str5 is:" << str5 << endl;
return 0;
}
2013年04月14日 10点04分 5
level 1
语言是C,头文件#include<string.h>但是源代码里面不能定义string变量
2015年02月26日 06点02分 6
1