Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Multiple files output

[es] :: C/C++ programiranje :: Multiple files output

[ Pregleda: 1646 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

onako

Član broj: 256314
Poruke: 75
*.dynamic.isp.telekom.rs.



Profil

icon Multiple files output25.04.2010. u 13:56 - pre 169 meseci
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,
 
Odgovor na temu

Eurora3D Team
Nebojsa - Programer & Vodja tima
Beograd

Član broj: 120376
Poruke: 900
*.dynamic.sbb.rs.



+7 Profil

icon Re: Multiple files output25.04.2010. u 16:26 - pre 169 meseci
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;
}

 
Odgovor na temu

kiklop74
Darko Miletić
Buenos Aires

Član broj: 78422
Poruke: 569
200.49.157.*

Sajt: ar.linkedin.com/pub/darko..


+13 Profil

icon Re: Multiple files output26.04.2010. u 13:35 - pre 169 meseci
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());
}


Tko leti vrijedi
 
Odgovor na temu

Mali Misha
Mihajlo Anđelković
NBGD

Član broj: 79396
Poruke: 379
91.185.103.*

ICQ: 195487525
Sajt: cpptea.com


+1 Profil

icon Re: Multiple files output26.04.2010. u 15:02 - pre 169 meseci
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. :)
Ipak se ++uje.
 
Odgovor na temu

[es] :: C/C++ programiranje :: Multiple files output

[ Pregleda: 1646 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.