相关疑难解决方法(0)

C++中字符串和char []类型之间的区别

我知道一点C,现在我正在看看C++.我习惯使用char数组来处理C字符串,但是当我看到C++代码时,我看到有使用字符串类型和字符串数组的示例:

#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;
}
Run Code Online (Sandbox Code Playgroud)

#include <iostream>
using namespace std;

int main () {
  char name[256], title[256];

  cout << "Enter your name: ";
  cin.getline (name,256);

  cout << "Enter your …
Run Code Online (Sandbox Code Playgroud)

c++ string types

118
推荐指数
4
解决办法
20万
查看次数

标签 统计

c++ ×1

string ×1

types ×1