相关疑难解决方法(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万
查看次数

std :: string是否包含null终止符?

下面的字符串是否包含空终止符'\ 0'?

std::string temp = "hello whats up";
Run Code Online (Sandbox Code Playgroud)

谢谢!:)

c++ string null

66
推荐指数
3
解决办法
6万
查看次数

标签 统计

c++ ×2

string ×2

null ×1

types ×1