文字列型
文字列型(String型)
複数のchar型で構成された型を文字列型という。要はchar型の配列。
#include <iostream> #include <string> using namespace std; int main(){ char str1[] = "hello"; string str2 = "hello"; cout << str1 << endl; cout << str2 << endl; }
char型の配列という考え方から、空文字「""」はnullではなく長さが0の文字列を表していることになる。
"10"は数値ではなく、数字という表現になるので注意。