I'm writing a simulation program in C++. I have several years programming experience but haven't done any at all in 15 years. It is my first time programming in C++. The simulation contains several hundred lines of code and works ok.
My primary goal is the simulation results. Im retired now, so acquiring c++ expertise isn't my primary goal though is still of interest.
I want to format the output results of the simulation into: console output I can read
CSV output I can put through Excel or equivalent
My plan is one routine that can print both formats.
From long examination of stringstream on stack overflow and youtube Im still stuck at square one. l I have two problems :
1: stringstream.str() wont compile
2: The call to fprintf doesn't want to recognise a string
I'm using netbeans 8.1 (standard compiler), zorin linux. Its my first experience of developing on both those platforms. I could write the code to do this myself, but I cant be the first person to want to do this stuff. fwiw the sample code was copied of answers and "howto" on the internet
here are the relevant snippets of code:
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include "globals.h"
#include "bjClass.h"
using namespace std;
extern FILE * resultsFile;
void print_disk_file(int outstream )
{
std::ostringstream s1;
int i = 22;
s1 << "Hello " << i << endl;
string s2 = s1.str(); // compiler says "unable to resolve str"
cout << s2;
// ...
ostringstream os;
os << "dec: " << 15 << " hex: " << std::hex << 15 << endl;
cout << os.str() << endl;
fprintf(resultsFile, "%s %c" , s1.str(), ' ') ; // compiler says "unable to resolve str" and gives warning about strings and char *
fprintf(resultsFile, "%s %c" , s2, ' ') ;
}