Thread: Multiple files output

  1. #1
    Registered User
    Join Date
    Mar 2010

    Multiple files output

    As a part of the project I'm working on multiple .ps files need be generated. Note the following:
    outputForGallery( int k) {
         std::string s;
         std::stringstream myOut;
         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 should be formed(in pics folder). However, I got the following error:
    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(""); would work, but I want this to be dynamic.

    Kind regards,

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > std::ofstream saveFile(fileName);
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

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