Multiple files output

This is a discussion on Multiple files output within the C++ Programming forums, part of the General Programming Boards category; As a part of the project I'm working on multiple .ps files need be generated. Note the following: Code: outputForGallery( ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    43

    Multiple files output

    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:fstream saveFile("something.ps"); would work, but I want this to be dynamic.

    Kind regards,

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > std::ofstream saveFile(fileName);
    Use
    std::ofstream saveFile( fileName.c_str() );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 02-25-2008, 05:35 AM
  2. Windows shell commands - multiple files
    By Magos in forum Tech Board
    Replies: 3
    Last Post: 02-28-2006, 12:56 AM
  3. Opening Multiple Files in sequence
    By wujiajun in forum C++ Programming
    Replies: 7
    Last Post: 01-16-2006, 07:47 PM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM
  5. opening multiple files sequentially
    By moonwalker in forum C Programming
    Replies: 5
    Last Post: 08-20-2002, 09:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21