新手问题,求c++高手指教
为什么这段代码没有输出?#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ifstream fin("my.txt");
if(!fin.is_open())
std::cout << "open error";
return 1;
std::string temp;
fin >> temp;
fin.close();
std::cout << '*' << temp << '*';
}
my.txt
This is a test file.
You can write something anywhere.
It has 70 chars.
It has 4 lines. 我粘贴了一下,然后代码就变成了这样
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ifstream fin("my.txt");
if(!fin.is_open())
std::cout << "open error";
return 1;
std::string temp;
fin >> temp;
fin.close();
std::cout << '*' << temp << '*';
}
找到原因了 if(!fin.is_open())
{
std::cout << "open error";
return 1;
}
要加个括号
页:
[1]