我知道一点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) 下面的字符串是否包含空终止符'\ 0'?
std::string temp = "hello whats up";
Run Code Online (Sandbox Code Playgroud)
谢谢!:)