Got one compiler diagnostic I can't handle

R

Richard Lionheart

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)
{
}
 
T

Tilman Kuepper

Hi Richard,
ostream file(sFilename.c_str()); // <<<< Line 29
// ^^^^^^^^^^^^^^ Line 29 ^^^^^^^^^

Try "ofstream" instead of "ostream".

Good luck,
Tilman
 
R

Richard Lionheart

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top