C++ 加上一句「;";抹去一切

C++ 加上一句「;";抹去一切,c++,iostream,ifstream,ofstream,endl,C++,Iostream,Ifstream,Ofstream,Endl,我第一次遇到这样的事情。代码应该接收一个包含数据的.txt文件,执行一些计算并输出一个.txt文件。我对这类事情有相当多的经验,但我遇到了一些我无法解释的事情。我没有改变我的机器、系统、编译器或任何东西。我已经缩短了一点代码来清理,但这是所有的主要代码 问题:出于某种原因,程序没有输出我在result之后编写的endl。您是否以二进制模式打开流?“您需要知道的是,流被称为“result”-您似乎已经知道问题出在哪里了。你是否尝试过删除所有你认为“不相关”的行,看看你是否能重现问题?如果不能,也许

我第一次遇到这样的事情。代码应该接收一个包含数据的.txt文件,执行一些计算并输出一个.txt文件。我对这类事情有相当多的经验,但我遇到了一些我无法解释的事情。我没有改变我的机器、系统、编译器或任何东西。我已经缩短了一点代码来清理,但这是所有的主要代码


问题:出于某种原因,程序没有输出我在
result之后编写的
endl
。您是否以二进制模式打开流?“您需要知道的是,流被称为“result”-您似乎已经知道问题出在哪里了。你是否尝试过删除所有你认为“不相关”的行,看看你是否能重现问题?如果不能,也许它们不是那么不相关。您是如何确定文件为空的?如果在Linux上,请尝试
hextump-C result.txt
。在任何其他系统上,查看文件大小或在十六进制编辑器中打开。文件中应该有5或6个字节。似乎你的新线翻译错了。我明天会回来提供更多信息,现在就赶飞机。谢谢你们的快速反应@杰西戈德-我想我没有。
#include <iostream> 
#include <cstdlib> 
#include <fstream> 
#include <cmath> 
#include <vector> 
#include <string>
#include <iomanip> 
#define _USE_MATH_DEFINES  using namespace std; 

//Declare Subprograms  string findFrames(string, int);

//Main Program  int main(void)  {

//Parameter
List----------------------------------------------------------------
    string shipSpec, Finding, Recommendation, Rectification,
            infilename, header, findFramesOutput, foundFrames;

    int        numOfRows;

    //Number of columns in input file
    int numOfColumns=26;

    //Number of letters to store after each finding of "fr."
    int numLetters=6;

//------------------------------------------------------------------------------


    //Setup input 
    ifstream raw; 
    cout << "Please enter the input file name> " << flush;
      while (true)
    {

        getline( cin, infilename );
        raw.open( infilename.c_str() );
        if (raw) break;
        cout << "Invalid file. Please enter a valid input file name> " << flush;
    } 

    cout << "Number of data rows?" "   "; 
    cin >> numOfRows;


    //Setup Output
    ofstream result; 
    result.open(string("processed_"+infilename).c_str()); 
    if (result.fail()) 
    { 
        cout << "Failed to open output file." << endl; 
        exit(1); 
    } 

    //Setup columnn headers
    int rowCounter; 
    int columnCounter;

    columnCounter = 0; 
    while (columnCounter < 2) 
    { 
        //Input header from ifsream 
        getline(raw, header, '\t'); 
        //Output header to ofstream 
        result << header << '\t'; 
        columnCounter+=1; 
    }

    //go through the rest of the headers, don't do anything
    while (columnCounter < numOfColumns)
    {
        raw>>header;
        result << header << '\t';
        columnCounter+=1;
    }

    //output column header for the list of frames
    result << "Found_Frames" << endl;

    //start in/outputting data.  Row counter starts at 1 now 
    rowCounter = 1; 
    while (rowCounter < numOfRows) 
    {
        //reset the column counter
        columnCounter = 0;
        while (columnCounter < numOfColumns)
        {
            //Input first two values which are the ship name and the report
            //ID number.
            while (columnCounter < 2)
            {
                string shipSpec;
                //Input name 
                raw >> shipSpec; 
                //Output name 
                result << setw(30) << shipSpec;
                columnCounter+=1;
            }

            //Read Findings/Rectifications/Recommendations
            while (columnCounter < numOfColumns)
            {
                //declare local variable to store the string of info
                string inString;
                //Input string until \t is encountered 
                getline(raw, inString, '\t');
                //Search and store frame numbers
                findFramesOutput = findFrames(inString, numLetters);
                //Append the output string to a global string variable
                foundFrames.append(findFramesOutput);
                //Add space to global string variable
                foundFrames.append(" ");
                //Output inString
                result << inString << '\t';
                //Reiterate to keep adding all the different frame number
                //findings
                columnCounter+=1;
            }

            //Output frame numbers (global variable)
            result << foundFrames;

            //Start a new line
            result << endl;
            rowCounter+=1;
        }
    }

    //Close input file 
    raw.close(); 


    //Close output file and return 
    result.close(); 
    return(0);
}