Again C++ question

Downing, Thomas Thomas.Downing at ipc.com
Mon Mar 28 14:38:25 BST 2005


It's not a compiler issue, it is a streams library implementation issue.

You may be able to sub-class basic_ofstream and gain access to the contained
basic_filebuf.  In the SGI implementation, you would then have two options -
create a new ctor, as the basic_filebuf implementation has a ctor that
takes an 'int fd' argument.  Or cleaner, you could add methods to handle
locking as the basic_filebuf gives you access to the fd.

I haven't looked at the GNU implementation closely, but I'm not sure if
this options is available in the same way.

td


-----Original Message-----
From: Mailing list agent on behalf of Claudiu ANGHEL
Sent: Mon 3/28/2005 8:17 AM
To: kdevelop at kdevelop.org
Subject: Re: Again C++ question
 
You are mixing C++ streams with C file libraries. You should consider 
ofstream::open. In c++ reference I do not find the constructor 
ofstream(int) but on msdn yes (non standard feature?!?!).
It is possible that was an already deprecated feature and gcc discarded 
it. Noting to do with kdevelop but gcc.

Muhammad Rizwan wrote:

>I am getting the following errors while compiling the code with adding
>#include <fstream> for file handling:
>
>*/home/hc7/chcmanager/src/CTCPServer.cpp:76: error: invalid conversion
>from `int ' to `const char*' 
>*/home/hc7/chcmanager/src/CTCPServer.cpp:76: error: initializing
>argument 1 of `std::basic_ofstream<_CharT,
>_Traits>::basic_ofstream(const char*, std::_Ios_Openmode) [with _CharT =
>char, _Traits = std::char_traits<char>]'
>
>Any idea?
>
>Regards,
>
>
>On Sat, 2005-03-26 at 22:12, Andreas Pakulat wrote:
>  
>
>>On 26.Mär 2005 - 19:37:47, Muhammad Rizwan wrote:
>>    
>>
>>>I was using kdevelop 2.XX one month ago, and write some code related to
>>>file handling as:
>>>
>>>	int fd;
>>>	if( (fd = open("file.txt", O_WRONLY | O_CREAT, 0640 ) == -1 )
>>>	{
>>>		Logging(strerror(errno), 0, ConfigData.Folder);
>>>		return(-1);
>>>	}
>>>	struct flock lockp;
>>>	lockp.l_type = F_WRLCK;
>>>	lockp.l_whence = SEEK_SET;
>>>	lockp.l_start = 0;
>>>	lockp.l_len = 0;
>>>	if( fcntl (fd, F_SETLK, &lockp) == -1 )
>>>	{
>>>		Logging(strerror(errno), 0, ConfigData.InsFolder);
>>>		close(fd);
>>>		return(-1);
>>>	}
>>>	ofstream outFile(fd);
>>>	outFile << "text here";
>>>	close(fd);
>>>
>>>I was compiling this program successfully in kdevelop 2.XX, but now i
>>>have updated my kdevelop version to 3.0 and i am getting errors for file
>>>descriptors i.e. fd.
>>>      
>>>
>>What errors specifically? I guess nobody can help you here without the
>>exact error messages....
>>
>>    
>>
>>>Now which function should i use to open file which 'll return me file
>>>descriptor, so that i 'll be able to lock file by using fcntl(). Because
>>>fcntl() accepts file descriptor (i.e. fd) as:
>>>      
>>>
>>open is a C-functions so you should checkt that you're including the
>>proper C-header and link against libc...
>>
>>Andreas
>>    
>>
>
>
>-
>to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
>unsubscribe ?your-email-address?
>
>
>  
>


-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe your-email-address



-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 4115 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kdevelop/attachments/20050328/447f3672/attachment.bin>


More information about the KDevelop mailing list