我了解一点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 回答
- 3 回答
- 0 关注
- 742 浏览
添加回答
举报
0/150
提交
取消