程序运行后什么也不显示,不知道是为什么


#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    char x;
    ifstream swp;
    swp.open("swp.txt");
    while (!swp.eof())
    {
        swp >> x;
    }
    cout << x;
    swp.close();
    return 0;
}

![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/684607925636118.png "=600 #left")

cout<<x写在循环里

你把cout写到了while循环的外面了
这导致你的这个char x,它会反复的被覆盖
如果你整个文档的最后一个字符是不可见的,比如空格或者换行,那可不啥也不显示吗