Hello I've looked around and there are some posts on this, and I've tried the fixes I found but still getting the error.
I'm using the Dev_C++ ver 5.11, MinGW compiler, I surmise I may not be able to use c_str with this compiler but figured I'd run it past you guys.
My entire brief only necessary (but compiled) code is below, showing the error and where it's occurring.
These are my compiler settings currently, although I've tried them all to no avail.
CXXFLAGS = $(CXXINCS) -std=gnu++11 -Wall -Wfatal-errors -g3 -fverbose-asm
CFLAGS = $(INCS) -std=gnu++11 -Wall -Wfatal-errors -g3 -fverbose-asm
The error is occurring about the last 3rd segment of the code on line 65
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <cstdlib>
using namespace std;
class Base{
public:
int iDbugPrtCt;
const char *ReVestFileName;
ofstream DrawDn_File;
ofstream ReVest_File;
Base();
~Base();
void Output();
int Re_InVestCalc();
}; // End of Base Class declaration
// Base Ctor
Base::Base()
{ iDbugPrtCt = 0; }
// Base Dtor
Base::~Base()
{ /*nothing yet*/ }
void Base::Output()
{
DrawDn_File.open("DrawDown.txt");
if (!DrawDn_File.good())
{ cerr << "Problem opening DrawDown file"; exit(1);
}
iDbugPrtCt++ ;
DrawDn_File << "Entered Output Func, output # " << iDbugPrtCt << "\n";
if (DrawDn_File.fail() )
{ cerr << "Failed write DrawDown file"; exit(1);
}
Re_InVestCalc();
iDbugPrtCt++ ;
DrawDn_File << "Back from Re_InVestCalc, output # " << iDbugPrtCt << "\n";
if (DrawDn_File.fail() )
{ cerr << "Failed write DrawDown file"; exit(1); }
} // End of Base::Output Func
int Base::Re_InVestCalc()
{ /* what I want is to insert a numerical counter in the filename
since later I will create a new file for each iteration. As you
see I've having trouble getting it into a const char ptr that
ofstream appears to require
*/
stringstream sItoS;
sItoS << iDbugPrtCt; // int to string,
const char* sFilename2 = "ReInvest_" ;
sFilename2 += sItoS.c_str + ".txt" ; //<-Draws error
// Error, std::stringstream has no member named 'c_str'
ReVestFileName = sFilename;
ReVest_File.open("ReInvest.txt", ios_base::out | ios_base::app );
if (!ReVest_File.good())
{ cerr << "Problem opening Re-invest file"; exit(1); }
}
iDbugPrtCt = iDbugPrtCt + 1 ;
ReVest_File << "Inside Re_InVestCalc, output # " << iDbugPrtCt << "\n";
ReVest_File << "sFilename is " << sFilename << "\n";
return 0;
} //End of Base::Re_InVestCalc Func
int main()
{
Base ObjRun;
ObjRun.Output();
//std::cin.get(); // Only for viewing output in real time.
return 0;
}