標準庫的string有一個substr函式用來擷取子字串。一般使用時傳入兩個引數,第一個是開始的座標(第一個字元是0),第二個是擷取的長度。
#include <iostream> #include <string> using namespace std; int main(int argc, char* argv[]) { string name("rockderia"); ,)); cout << firstname << endl; system("pause"); }
輸出結果 rock