Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/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++ - Fatal编程技术网

C++ 如何使文本文件与读取不同输入的文本文件在同一行下

C++ 如何使文本文件与读取不同输入的文本文件在同一行下,c++,C++,我需要让我的输出像这样 申请人#:1 学校=L GPA=4.0数学=600语言=650校友=N 申请文科 接受文科!!! 但是,当我运行代码时,它只是将输入放在每个地方,而没有进入文本文件 #include <iostream> #include <fstream> using namespace std; int main() { // Open both input and output ifstream input; input.open

我需要让我的输出像这样

申请人#:1
学校=L GPA=4.0数学=600语言=650校友=N
申请文科
接受文科!!!
但是,当我运行代码时,它只是将输入放在每个地方,而没有进入文本文件

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    // Open both input and output
    ifstream input;
    input.open("MP2input.txt.");
    ofstream output;
    output.open("MP2output.txt");

    // containers for any variables
    double app = 0;
    string pass;

    if(!input.fail())
    {
        do(input >> pass)
        {
            app++;
            output << "Application #" << app << endl;
             output << "School = " << pass <<  " GPA = "  << pass << " Math = " << pass << " Verbal = " << pass << " Alumnus = " << pass << endl;
        }
    }
    input.close();
    output.close();
}
输出如下所示

应用程序#1
学校=L GPA=L数学=L语言=L校友=L
应用程序#2
学校=4.0 GPA=4.0数学=4.0语言=4.0校友=4.0
应用程序#3
学校=600 GPA=600数学=600语言=600校友=600
应用程序#4
此处:

   do(input >> pass)
   {
       app++;
       output << "Application #" << app << endl;
        output << "School = " << pass <<  " GPA = "  << pass << " Math = " << pass << " Verbal = " << pass << " Alumnus = " << pass << endl;
   }

如果您确信您的输入文件格式正确,每次只需更新输入的pass


int main()
{
//打开输入和输出
ifstream输入;
打开(“MP2input.txt”);
流量输出;
output.open(“MP2output.txt”);
//任何变量的容器
双app=0;
串通;
如果(!input.fail())
{
do(输入>>通过)
{
app++;

输出成功了。非常感谢。我对编码和堆栈溢出都是新手。
std::string school;
std::string GPA; 
// ... others ...
while(input >> school >> GPA) {
    app++;
    output << "Application #" << app << endl;
    output << "School = " << school <<  " GPA = "  << GPA << endl;
    // ... others ...
}