LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-18-2008, 10:59 AM   #1
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Compile problem with C++ (older code)


I'm trying to compile some older code written in C++ and am getting this error:
log.cpp: In constructor `Log::Log(std::string)':
log.cpp:36: error: no matching function for call to `std::basic_ofstream<char, std::char_traits<char> >:pen(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, const std::_Ios_Openmode&)'
/usr/lib/gcc/i486-slackware-linux/3.4.6/../../../../include/c++/3.4.6/fstream:695: note: candidates are: void std::basic_ofstream<_CharT, _Traits>:pen(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
make[1]: *** [log.o] Error 1


The file log.cpp contains this:
Code:
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

#include "log.h"

/**
 * Opens up a log file called \e fname for appending.
 *
 * \param fname the name of the file to log to.
 */
Log::Log ( string fname )
{

	logfile.open ( fname.begin (  ), ios::app );
}

/**
 * Records a string to the log file
 *
 * \param s the string to be appended to the log file
 */
void Log::record ( string s )
{
	logfile << s << endl;
}

/**
 * Closes down the log file
 */
Log::~Log (  )
{
	logfile.close (  );
}
Can anyone suggest how to fix this? I am using gcc-3.4.6 with glibc-2.3.6 (but preferably the fix should work with gcc-4.x and glibc>=2.4).
 
Old 06-18-2008, 11:16 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
The error message is telling you it does not have an open function which accepts an iterator, yet it has a function which excepts c style string so just pass c_str to it. Actually all the opening could be done in the initialisation list (but that is a different point)
Code:
logfile.open ( fname.c_str(  ), ios::app );
 
Old 06-18-2008, 03:44 PM   #3
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Original Poster
Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Thanks, that fixed it!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem compile Ndiswrapper source code bourne Linux - Software 8 02-20-2007 07:35 PM
how can I compile older versions of gcc? drkstr Slackware 11 06-11-2006 11:10 AM
compile/linker problem with simple libipq code TheLinuxDuck Programming 7 05-06-2005 01:28 PM
Compile problem with souce code neilcpp Linux - Software 3 10-18-2003 01:53 PM
Trying to compile older make of libc, getting error Cecil Linux - Software 0 07-16-2003 02:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration