I've got a program that has three different classes, all of which have their own pointer to an class called ObsFileName, who's main functionality is to store the name of an output file individual to the class, and return it with a function value(). All throughout the program, when a certain type of event is triggered, the class it coincides with outputs to the ofstream, like this:

std::ofstream observationData;
observationData.open (ObsFileName->value().c_str(), std::ios::app);
observationData << "8,";
observationData.close();

So, in my program, I've got three classes. Component1, Component2, and Component3, and their output files contain:

Component1-obs.txt: 1,3,1,3,1,4,1,4,1,4,1,4,1.....
Component2-obs.txt: ⰷⰷⰵⰷⰵⰷⰵⰷⰵⰷⰵⰷⰷⰷⰷⰷⰷⰷⰵⰷⰷⰵⰷ....
Component3-obs.txt: 8,8,9,12,8,8,9,12,9,12....

Any idea why Component2 keeps outputting the wackyness? (Yes that's a technical term.) It's initialized, etc., in all the same ways as Component1 and Component3.

Any help would be greatly appreciated.

Post the section of code that is used to write to the Component2-obs.txt. The code you posted does not tell us enough information to answer your question.

It's the same section of code for all three classes, they're all generated by the same code generator, the only difference being the name of the output file and the comma delimited integer that's output to the stream.

In Component2-obs.txt, it's that same block of code in two different places (representing two different events), and the only thing that's different is which comma delimited integer is output.

Initialization..

// Default initialization for observation file.
ObsFileName = new obsFileName;
ObsFileName->value() = "Component2-obs.txt";
// End default initialization.

Instance 1..

// If StateTransition, output trans to output file
std::ofstream observationData;
observationData.open (ObsFileName->value().c_str(), std::ios::app);
observationData << "5,";
observationData.close();
// End StateTransition

and Instance 2:

// If StateTransition, output trans to output file
std::ofstream observationData;
observationData.open (ObsFileName->value().c_str(), std::ios::app);
observationData << "7,";
observationData.close();
// End StateTransition

Would any other surrounding code be useful? Unfortunatly, I'm somewhat stuck with the structure of the code around my additions because I'm extending an already existing program.

Just got back to working on this, and I realized that if I open the *.txt file that I'm creating in Notepad, it won't display correctly, but if I open it in WordPad (or MATLAB) it will. Are there any sort of formatting options that I might need to set in my ofStream initialization that might be creating this?

The mystery deepens: If I open the file in notepad, and delete some amount of the boxes, when I try and re-open it in wordpad, the boxes are now present in wordpad as well.

But! If I open it in matlab, this character is put in front of all text that was there: ÿþ

Otherwise, the file is the same (sans the deletions I did at the end.) I'm assuming it has something to do with the encoding, which I'm somehow editing by deleting at the EOF in notepad.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.