Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Aug 24th, 2007, 5:56 PM   #1
Lesliect6
Programmer
 
Join Date: Aug 2005
Posts: 68
Rep Power: 4 Lesliect6 is on a distinguished road
wxFile problem

Hello,

I have been trying to figure this out myself, but without success. I have recently started wxWidgets programming, and I was trying to find a way to write a string to an existing file. The name of the file is a string which I extract from a textBox. Now, in wxWidgets, the string type contained in a textBox is a wxString, so I cannot use it with the standard ofstream. There is a wxFile class, but the Write() method produces a weird error. Here is the code and the error message :

wxFile *file_to_write_to = new wxFile(WxEdit1->GetLineText(1));
if (!file_to_write_to->IsOpened()) // if error while opening file
    ErrorDialog->ShowModal();
else // if file could be opened
{
    file_to_write_to->Seek(pos); // go to a given position in the file
    wxString x="string to write";
    file_to_write_to->Write(x);
    delete file_to_write_to;
}

The program compiles correctly, but when I try to execute this code, I get :

can't write to file descriptor 3 (error 5: access refused)

Now I am pretty sure I have access to everything on my computer, I am in Administrator mode, the file I am opening is just an example file created using Notepad, "example.txt", there are no writing restrictions, no read-only, everything is fine. I get this error with every other file too. I narrowed down the problem and what I can be sure of is that the file IS opened successfully. The problem occurs after the "delete file_to_write_to;", even if I change it to "file_to_write_to->Close();". However, nothing is written to the file.

If there is an easier way to write to a file, please let me know, or help me out with this code, which appears to me to be logical.

Thank you,

Leslie
Lesliect6 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
<td> height problem grimpirate HTML / XHTML / CSS 19 May 4th, 2007 6:01 AM
Changing icons problem Pedja C# 8 Mar 25th, 2006 8:03 AM
cgi/perl script + IE problem joyceshee Perl 2 Jan 24th, 2006 11:10 AM
help with recursion problem the_new_guy_in_town Java 3 Apr 7th, 2005 3:04 AM
string problem when passing in linked list quantz C++ 0 Feb 27th, 2005 10:11 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:00 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC