Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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++中用文件进行训练。我有一个问题:如果我在终端中写了超过1个字,那么在文件中我只写了第一个字_C++_File_Input_Output - Fatal编程技术网

用C+在文件中输入长短语+; 我在C++中用文件进行训练。我有一个问题:如果我在终端中写了超过1个字,那么在文件中我只写了第一个字

用C+在文件中输入长短语+; 我在C++中用文件进行训练。我有一个问题:如果我在终端中写了超过1个字,那么在文件中我只写了第一个字,c++,file,input,output,C++,File,Input,Output,范例 大家好,开发人员 在文件中,我只有 你好 下一次,我将执行程序,新单词将出现在下一行 代码 #include <cstdlib> #include <iostream> #include <fstream> using namespace std; /* * */ main(int argc, char** argv) { string test; string st; ofstream biblio; bi

范例

大家好,开发人员

在文件中,我只有

你好

下一次,我将执行程序,新单词将出现在下一行

代码

#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

/*
 * 
 */

main(int argc, char** argv) {
    string test;
    string st;

    ofstream biblio;
    biblio.open("lis.txt", ios::app);

    if(biblio.is_open()){
        cout <<" Write in file: ";
        cin >> test;
        biblio << test << "\n";
        biblio.close();
        cout<<"I'm in the if!!!\n";
    }

    ifstream biblio1;
    biblio1.open("list.txt");
    if(biblio1.is_open()){
        while(getline(biblio1,st)){
            cout << st << '\n';
        }
        cout<<"I'm in the other if!!!\n";
        biblio1.close();
    }
    else{
        cout<<"Not possible to open the file\n";
    }
}
#包括
#包括
#包括
使用名称空间std;
/*
* 
*/
主(内部argc,字符**argv){
串试验;
字符串st;
流图书馆;
图书馆开放(“lis.txt”,ios::app);
如果(图书馆是开放的()){
库特试验;

biblio操作员
>
使用空格来描绘项目,使用
(std::cin,test)
代替。

操作员
>
使用空格来描绘项目,使用
(std::cin,test)
代替。

cin>>test
,只读取一个字。
cin>>test
,只读取一个字。