Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Got one compiler diagnostic I can't handle

Reply
Thread Tools

Got one compiler diagnostic I can't handle

 
 
Richard Lionheart
Guest
Posts: n/a
 
      03-22-2006
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)
{
}

 
Reply With Quote
 
 
 
 
Tilman Kuepper
Guest
Posts: n/a
 
      03-22-2006
Hi Richard,

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


Try "ofstream" instead of "ostream".

Good luck,
Tilman


 
Reply With Quote
 
 
 
 
Richard Lionheart
Guest
Posts: n/a
 
      03-22-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is this compiler diagnostic legal? Rainer Zufall C Programming 10 02-12-2008 06:40 AM
INT_MIN and compiler diagnostic p_cricket_guy@yahoo.co.in C Programming 41 03-26-2007 03:47 AM
Possible to handle web requests without an ASPX page? i.e. have DLL handle request. jdlwright@shaw.ca ASP .Net 2 05-31-2005 05:42 PM
how to handle command line output(not terminal handle) Leon Python 2 11-04-2004 05:16 AM
File Handle Reading Blues: Rereading a File Handle for Input Dietrich Perl 1 07-22-2004 10:02 AM



Advertisments