#include <string> using std::string;
string s1; string s2(s1); string s3("value"); string s4(n,'c');
方法 | 描述 |
---|---|
s.size() | 返回s中字符的個數 |
‘\0’ 不在字符計數範圍內但 \n等在計數的範圍內。c++
庫類型通常包含一些配套類型,配套類型是一種抽象類型,目的是使庫類型的使用與機器無關。code
約束:
from c++ primer 4th. p76對象
- 索引下標的類型 string::size_type
- 索引的取值範圍 0 -- s.size()-1
string 是否包含‘\0’ ?索引
from vs2005字符串
s[s.size()] 爲‘\0’string
約束table
from c++ primer 4th. p75class
‘+’ 操做符的左右操做數必須至少有一個是string類型.方法
string s1 = "hello"; string s2 = "word"; string s3 = s2 + "you"; // ok string s4 = "hello" + "you"; // error string s6 = "hello"+"you"+s2; // error