Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从文件系统读取_C++_File_File Io - Fatal编程技术网

C++ 从文件系统读取

C++ 从文件系统读取,c++,file,file-io,C++,File,File Io,这是我程序的一个摘录-我想显示存储在输出窗口中的文本。文本将根据需要存储在文件中。但是,在阅读时,内容不会显示在屏幕上。应该做什么改变 ofstream out("Welcome"); out<<" WELCOME TO MAIN BANK ATM SIMULATOR "<<endl; out<<"Select operation mode:\n1. Administrator Mode\n2. User Mode\n3. Exit"<<endl;

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

ofstream out("Welcome");
out<<" WELCOME TO MAIN BANK ATM SIMULATOR "<<endl;
out<<"Select operation mode:\n1. Administrator Mode\n2. User Mode\n3. Exit"<<endl;
out.close();

ifstream in("Welcome");
char asd[100];
in>>asd;
cout<<asd<<endl;
in.close();
getch();
return 0;
“欢迎”的“代码”;
out在“欢迎”之后有一个空格。由于空间关系,它将结束阅读。因此,如果没有空格,它将只显示“欢迎”,然后它将显示整个字符串。

在.get(asd,100)中使用
(请参阅)

我通常发现流式传输到字符串而不是字符数组更容易。 std::字符串s; 在>>年代; 库特<
有关将整个文件读入字符串的信息,请参见本主题

您的大多数输出都将进入名为
Welcome
的文件。然后,应该从该文件中读取“欢迎”并显示在屏幕上,但其余的将不会被读取或显示。