C++使用ifstream读取文件

#include < iostream >
#include < fstream >
#include < string >

using namespace std;
int main()
{
    
    
	std::locale::global(std::locale(""));//读取带有中文路径的文件
	char file_name[100] = "text.txt";
	string dir = file_name;
	ifstream in_fil(dir.c_str());
	string line_file
	if (in_fil.is_open())
	{
    
    
		printf("Open success!!!\r\n");
		while(getline(in_fil, line_file))
		{
    
    
			printf("%s", line_file.c_str());
		}
	}
	else
	{
    
    
		printf("Open fail error code:%d\r\n", GetLastError());
	}
}

猜你喜欢

转载自blog.csdn.net/qq_30727593/article/details/127428188