int get();
此函数从输入流中读入一个字符,返回值就是该字符的 ASCII 码。如果碰到输入的末尾,则返回值为 EOF。
#include <iostream>
using namespace std;
int main()
{
int c;
while ((c = cin.get()) != EOF)
cout.put(c);
return 0;
}
程序运行情况如下:
http://c.biancheng.net/cplus/↙
http://c.biancheng.net/cplus/
C++ Tutorial↙
C++ Tutorial
^Z↙
↙表示回车键,^Z表示 Ctrl+Z 组合键。
#include <iostream>
using namespace std;
int main()
{
int c;
freopen("test.txt", "r", stdin); //将标准输入重定向为 test.txt
while ((c = cin.get()) != EOF)
cout.put(c);
return 0;
}
版权说明:Copyright © 广州松河信息科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州松河信息科技有限公司 版权所有