Got one compiler diagnostic I can't handle

Discussion in 'C++' started by Richard Lionheart, Mar 22, 2006.

  1. Hi All,

    I'm running Visual Studio .Net, but I couldn't see how to build a ver.
    6.0-style VC++ style program, so I'm using it to write a .cpp file and
    then using the command-line compile/link instruction.

    I copied a program of Josuttis from his web site, plugged it into my
    little structure and got one diagnostic:

    UpdatePresentersData.cpp(29) : error C2664:
    'std::basic_ostream<_Elem,_Traits>::basic_ostream(std::basic_streambuf<_Elem
    ,_Traits> *,bool)' : cannot convert parameter 1 from 'const char *' to
    'std::basic_streambuf<_Elem,_Traits> *'
    with
    [
    _Elem=char,
    _Traits=std::char_traits<char>
    ]
    and
    [
    _Elem=char,
    _Traits=std::char_traits<char>
    ]
    Types pointed to are unrelated; conversion requires
    reinterpret_cast, C-style cast or function-style cast

    The offending line, #29, is flagged in the code below. I'd appreciate
    any suggestion on how handle this problem.

    Thanks in advance,
    Richard

    #include <string> // for strings
    #include <iostream> // for I/O
    #include <fstream> // for file I/O
    #include <iomanip> // for setw()
    #include <cstdlib> // for exit()
    using namespace std;

    // Complile and link with:
    // cl UpdatePresentersData.cpp /EHsc
    // In SciTE, use [Shift] F6 to switch buffers.

    // Forward declarations
    void writeCharsetToFile(const string& sFilename);
    void outputFile(const string& sFilename);

    int main() {
    std::cout << "Starting UpdatePresentersData" << std::endl;

    writeCharsetToFile("charset.out");
    outputFile("charset.out");

    std::cout << "Press ENTER to close this window" << std::endl;
    char c = getchar();
    }

    void writeCharsetToFile(const string& sFilename)
    {
    // Open output file
    ostream file(sFilename.c_str()); // <<<< Line 29
    // ^^^^^^^^^^^^^^ Line 29 ^^^^^^^^^

    // File opened?
    if (! file)
    {
    // No! Abort program
    cerr << "Can't open output file \"" << sFilename << "\"" << endl;
    exit (EXIT_FAILURE);
    }

    // Write character set
    for (int i=32; i<256; i++)
    {
    file << "value: " << setw(3) << i << " "
    << "char: " << static_cast<char>(i) << endl;
    }
    }

    void outputFile(const string& sFilename)
    {
    }
    Richard Lionheart, Mar 22, 2006
    #1
    1. Advertising

  2. Hi Richard,

    > ostream file(sFilename.c_str()); // <<<< Line 29
    > // ^^^^^^^^^^^^^^ Line 29 ^^^^^^^^^


    Try "ofstream" instead of "ostream".

    Good luck,
    Tilman
    Tilman Kuepper, Mar 22, 2006
    #2
    1. Advertising

  3. Hi Tilman,

    > Try "ofstream" instead of "ostream".


    You are so right. You could have used the imperative: Use "ofstream"
    instead of "ostream", Dummy!

    Thank you for taking the trouble to help me.

    Yours truly,
    Richard
    Richard Lionheart, Mar 22, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Johnson Sr.

    System.Diagnostic.Process and disfunctional process

    Michael Johnson Sr., Feb 17, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,953
    Michael Johnson Sr.
    Feb 17, 2004
  2. Michael Johnson Sr.

    System.Diagnostic.Process and disfunctional process.

    Michael Johnson Sr., Feb 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    318
    Michael Johnson Sr.
    Feb 17, 2004
  3. Andrew

    Managing Diagnostic Listener Files

    Andrew, Aug 5, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    485
    Andrew
    Aug 6, 2004
  4. INT_MIN and compiler diagnostic

    , Feb 28, 2007, in forum: C Programming
    Replies:
    41
    Views:
    1,182
    Chris Torek
    Mar 26, 2007
  5. Rainer Zufall

    is this compiler diagnostic legal?

    Rainer Zufall, Feb 11, 2008, in forum: C Programming
    Replies:
    10
    Views:
    488
    Thad Smith
    Feb 12, 2008
Loading...

Share This Page