1、C++中如何定义字符串?
string str;//声明str
str="hello"//初始化为hello
2、C++中如何计算字符串的长度?
string str;
str = "hello,world!";
len = str.length();
3、C++中如何得到字符串的每一个字节?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a="abcdefghigklmn";
string b="def";
string c="123";
string::size_type idx;
idx=a.find(b);//在a中查找b.
if(idx == string::npos )//不存在。
cout << "not found\n";
else//存在。
cout <<"found\n";
idx=a.find(c);//在a中查找c。
if(idx == string::npos )//不存在。
cout << "not found\n";
else//存在。
cout <<"found\n";
return 0;
}