#include<iostream> using namespace std; #include<string> int main() { //string 的empty和size操作 string s1; if (s1.empty()) { cout << "空的" << endl;//空的 } else { cout << "不是空的" << endl; } string s2("12345"); cout << "s2的位數(shù):" << s2.size() << endl; //s2的位數(shù):5 auto a = s2.size();//a=5;,a.size()返回的是無符號數(shù), int b = -10; if (a > b)//int 和 無符號 相比較,,int 轉(zhuǎn)換為無符號 { cout << "a>b" << endl; } else { cout<< "a<b" << endl; } // a<b //sring的== > < //string 的+ string a1 = "aga"; string a2 = "agrq"; string a3 = a1 + a2; cout << "a3: " << endl; string a4 = "sagrwa" + a3; cout << "a4:" << a3 << endl; //string a5 = "sgws" + "sgwgger";//報錯 string +,左右必有一個string,不能全是字面值 system("pause"); }
|
|
來自: 木俊 > 《c primer》