C++ 输入/输出(一)

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 
#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' <


你可能感兴趣的:(C++)