Добавление & quot; endl & quot; стирает все

Впервые я столкнулся с чем-то подобным. Код должен принимать в файл .txt с данными, выполнять некоторые вычисления и выводить файл .txt. У меня довольно большой опыт работы с такими вещами, но я столкнулся с чем-то, что не могу объяснить. Я не изменил свою машину, систему, компилятор или что-то еще. Я немного сократил код для очистки, но это все основной код.

ПРОБЛЕМА: по какой-то причине программа не выводит endl что я написал после result << "Found_Frames" << Я перепробовал все виды вещей. Я поместил некоторые результаты тестов до, после, и поведение для всех этих тестов было довольно абсурдным. Иногда тестовый текст будет напечатан, но как только я добавлю endl в строке тестового текста тестовый текст исчезнет при следующем запуске программы.

#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);
}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector