Again C++ question

Claudiu ANGHEL claudiu.anghel at skynet.be
Mon Mar 28 14:17:06 BST 2005


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«



More information about the KDevelop mailing list