我了解一點C,現在來看看C ++。我習慣于使用char數組來處理C字符串,但是當我看C ++代碼時,我看到有同時使用字符串類型和char數組的示例:#include <iostream>#include <string>using namespace std;int main () { string mystr; cout << "What's your name? "; getline (cin, mystr); cout << "Hello " << mystr << ".\n"; cout << "What is your favorite team? "; getline (cin, mystr); cout << "I like " << mystr << " too!\n"; return 0;}和#include <iostream>using namespace std;int main () { char name[256], title[256]; cout << "Enter your name: "; cin.getline (name,256); cout << "Enter your favourite movie: "; cin.getline (title,256); cout << name << "'s favourite movie is " << title; return 0;}(兩個示例均來自http://www.cplusplus.com)我想這是一個被廣泛詢問和回答的(顯而易見的)問題,但是如果有人能告訴我這兩種處理C ++中的字符串的方式(性能,API集成,每種方式的區別)到底有什么區別,那將是很好的。更好...)。謝謝。
- 3 回答
- 0 關注
- 762 瀏覽
添加回答
舉報
0/150
提交
取消