cout.precision(2); //保留小数点后两位
cout.setf(ios::fixed, ios::floatfield);
//输入多个值
//输入多个数值
int fir, sec;
while (cin >> fir >> sec) { //cin用于循环表达式,返回bool值
cout << "两个数" << endl;
}
cout << "不满足两个都是指定类型值" << endl;
//判断输入值类型是否合法
if (!cin)
{
cout << "bad" << endl;
}
//EOF(-1) 先执行!= 再将bool值赋给ch
int ch;
while ( (ch = cin.get() != EOF)) {
cout.put((char)ch);
if (ch == true)
{
cout << ch << "ch" << endl;
}
//判断输入结束 '\n'
int ch;
while ( (ch = cin.get())) {
cout.put((char)ch);
// cout << "EOF" << endl;
}
#include <iostream>
#define 你好 88
//命名空间,省去std::头
using namespace std;
void muFunction(void);
int main(int argc, const char * argv[]) {
string s = "fuck 这就是 C++的 string";
//输出函数
cout << "命名空间起作用了" << endl << "哪个混蛋又去调高空调" << endl << s; // endl = "\n"
cout << "\n请输入点东西\n" << "\n";
//输入函数和cin.get
char c[25];
cin >> c;
cin.get(c, 25);
char ch;
cin.get(ch);
//printf 和 cout 区别
//cout可以自动识别变量类型,printf需要相对的类型占位,cout属于高级
printf("printf: %s",c);
cout << "cout: "<< c << endl;
//C++ 语法风格
//由于C++的自由格式规则将标记间的换行符和空格看作是可相互替换的。当代码行很长,限制输 出的显示风格时,最后一种技术很方便。
cout << "c++"
<< "sec"
<< "third"
<< c
<< endl;
muFunction();
cout << 'M' <<endl;
cout.put('M'); //C++ Relese 2.0之前,单字符是被存储为int型,输出int型,所以有有.put('M')输出单字符
//C++ 数组语法,省略等号
const int code = 10;
char cc[] {'a','y'};
char *q = "sdsdf"; //c++11 对这种C风格的字符串常量表示警告
char *qqqqq[] = {"sdf"};
//以下格式这样可以
char ca[] = "sdfsdf";
char qq = 'a';
char qqq[] = "sdfsdf";
char qqqq[] = {'q','q'};
//自动数据类型 auto (比较少普及)
auto a_c = 'a'; //char
auto a_f = 1.0; //float
auto a_i = 1; //int
size_t s_a_c = sizeof(a_c); //1字节
size_t s_a_f = sizeof(a_f); //8字节
size_t s_a_i = sizeof(a_i); //4字节
//强转
char t = 你好; //88;
char t2 = 'X';
int a = (int)t;
a = (int)t2;
cout << t << endl << t2 << endl;
return 0;
}
void muFunction()
{
cout << __FUNCTION__ << endl;
}