[ onako @ 25.04.2010. 13:56 ] @
As a part of the project I'm working on multiple .ps files need be generated. Note the following:
Code:

outputForGallery( int k) {
     std::string s;
     std::stringstream myOut;
     myOut<<k;
     s=myOut.str();
     std::string fileName="pics/forGallery";
     fileName.append(s); fileName.append(".ps");
     std::ofstream saveFile(fileName);

This means if 0 is passed as a parameter, file with filename forGallery0.ps should be formed(in pics folder). However, I got the following error:
Code:

error: no matching function for call to ‘std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::string&)’
/usr/include/c++/4.4/fstream:623: note: candidates are: std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/fstream:608: note:                 std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/iosfwd:84: note:                 std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const std::basic_ofstream<char, std::char_traits<char> >&)

Any suggestions on how to avoid this, or other ideas to print files with different filenames are very welcome. I understand that
std::ofstream saveFile("something.ps"); would work, but I want this to be dynamic.

Kind regards,
[ Eurora3D Team @ 25.04.2010. 16:26 ] @
Code:

#include <iostream>

using namespace std;

void outputForGallery( int k)
{

    char buffer[10];

    string fileName="pics/forGallery";
    fileName.append(itoa(k, buffer, 10)); // < itoa, int to ascii
    fileName.append(".ps");
    cout << fileName << endl;
    //std::ofstream saveFile(fileName);
}

int main(int argc, char *argv[])
{
    outputForGallery(0);

    return 0;
}
[ kiklop74 @ 26.04.2010. 13:35 ] @
Ih bre, pa nemoj tako. Ako covek hoce da koristi STL onda evo STL-a:

Code:


#include <iostream>
#include <fstream>
#include <string>
#include <sstream>



template<typename ValueType>
std::string ConvertToString(ValueType value) {
    std::stringstream ss;
    ss << value;
    return ss.str();
}


void outputForGallery(int k) {
     std::string s (ConvertToString(k));
     std::string fileName("pics/forGallery");
     fileName += s;
     fileName += ".ps";
     std::ofstream saveFile(fileName.c_str());
}

[ Mali Misha @ 26.04.2010. 15:02 ] @
Da, ja bih samo pozvao c_str() i završena priča.

Inače, iz naslova teme bi se moglo reći da će se sresti i vektor ofstreamova. :)