从文件系统读取

Reading from File system

本文关键字:读取 文件系统      更新时间:2023-10-16

这是我的程序的摘录-我想显示存储在输出窗口中的文本。文本根据需要存储在文件中。但是,在阅读时,内容不显示在屏幕上。应该做出哪些改变?

ofstream out("Welcome");
out<<" WELCOME TO MAIN BANK ATM SIMULATOR "<<endl;
out<<"Select operation mode:n1. Administrator Moden2. User Moden3. Exit"<<endl;
out.close();
ifstream in("Welcome");
char asd[100];
in>>asd;
cout<<asd<<endl;
in.close();
getch();
return 0;

在"Welcome"后面有一个空格。由于空格,它结束了读取。所以它只会显示"Welcome",如果没有空格,那么它会显示整个字符串

使用in.get(asd, 100)(见这里)

我通常发现将流转换成字符串比转换成字符数组更容易。std:: string s;In>> s;cout<<p>请参阅本主题,以将整个文件读取为字符串https://stackoverflow.com/a/4457291/2212458