Thanks to both replies, could you please help me on this new confusion? I don't readily understand why I got the error. ( labeled with comment just after -> sName.clear(); )
Code:
int ReVestCls::Re_InVestCalc()
{
stringstream ssName;
ssName << "ReInvest_" << iPeriod_Ct << ".txt";
string sName(ssName.str());
const char* ccpFilename = sName.c_str();
ofstream ofstr_ReVest(ccpFilename); // Open new ReVest file
if (!ofstr_ReVest.good())
{ cerr << "Problem opening ReVest file" << endl; exit(1); }
// Initial output data ** Prints only once at top of file ** //fDrawDownPmt is a Class var
ofstr_ReVest << fixed << setprecision(2) << "Initial purchase Deposit " << fDrawDownPmt << endl;
int i = 1;
while( i < iPeriod_Ct)
{
ofstr_ReVest.close();
ofstr_ReVest.clear();
ssName.str("");
ssName.str( std::string() ); // overkill here from desperation
ssName.clear();
ssName << "ReInvest_" << i << ".txt";
sName.clear();
// sName(ssName.str()); //<-[Error] no match for call to '(std::string {aka std::basic_string<char>}) (std::basic_stringstream<char>::__string_type)'
// ccpFilename = sName.c_str();
string sName2(ssName.str()); // different string fixes ?
ccpFilename = sName2.c_str();
ofstr_ReVest.open(ccpFilename, ios_base::out | ios_base::app ); // append mode, Open pertinent ReVest file
// No code created here yet, just the simple test write below.
ofstr_ReVest << "value for i is " << i << " Value for iPeriod_Ct is " << iPeriod_Ct << endl;
i++;
}
cout << " Leaving Re_InVestCalc Func" << endl;
return 0;
}