1.字符串类型
(1)C风格的字符串 char str1[]="abcd "
(2)C++风格字符串 string str2="abcd"
特别注意:在使用第二种 string str2="abcd"是,一定要引用头文件<string>
#include <iostream>
#include<string>
using namespace std;
int main()
{
//C风格字符串
char str1[]=" ";
cin>>str1;
cout<<str1<<endl;
//(2)C++风格 注意 引用头文件 #include<string>
string str2="helloworld";
cout<<str2<<endl;
string str3="777";
cin>>str3;
cout<<str3;
return 0;
}
2.布尔类型
(1)bool类型只有两个结果 ture为1,false为0
(2)查看bool类型所占空间(1)
#include <iostream>
using namespace std;
int main()
{
bool flag=true;
cout<<flag<<endl;
bool flag=false;
cout<<flag<<endl;
//计算bool类型所占空间
cout<<sizeof(bool);
return 0;
}