三十五.C++ 的cout输出,cin输入

    技术2022-07-12  67

    一. 用cout输出

    #include<iostream> using namespace std; int main() { int n = 6; double f = 4.9; char c = 'a'; cout << "n=" << n <<",f=" << f << endl; cout << 123 << ",c=" << c; return 0; }

    二. 用cin输入

    #include<iostream> using namespace std; int main() { int n1,n2; double f; char c; cin >> n1 >> n2 >> c >> f; cout << n1 <<","<< n2 << "," << c << "," << f; return 0; }

    用cin读入所有输入的字符,包括空格,回车

    #include<iostream> using namespace std; int main() { int c; while((c=cin.get())!=EOF)//EOF判断是否输入结束,c要定义为int型 { cout << (char)c; } return 0; }
    Processed: 0.068, SQL: 10