|
|
Hi all,
I am writing a VC++6.0 application. I need to read from a text file and display the file content in an Edit Box. I use the following codes:
CEdit m_fileContent;
CFile pFile;
m_fileContent.SetWindowText(""); //clear
pFile.open(.....);
int length = pFile.GetLength();
CString* strContent = new CString("");
pFile.Read(strContent->GetBuffer(0),length);
m_fileContent.SetWindowText(strContent->GetBuffer(0)); //update file content
strContent->ReleaseBuffer(0);
delete strContent;
pFile.Close();
Now the problem is: When I first opened a file, it's fine. But When I opened a second file, if the length of the first file is longer than that of the second file, the content is not cleared. Any ideas? thanks,
Gavin
|
|
|
|
|
CEdit m_fileContent;
CFile pFile;
m_fileContent.SetWindowText("");
pFile.open(.....);
int length = pFile.GetLength();
CString strContent = _T("");
pFile.Read(strContent.GetBuffer(0),length);
strContent.ReleaseBuffer();
m_fileContent.SetWindowText(strContent);
pFile.Close();
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks a lot Zac and David!
|
|
|
|
|
Try:
CString strContent;
pFile.Read(strContent.GetBuffer(length), length);
strContent.ReleaseBuffer();
pFile.Close();
m_fileContent.SetWindowText(strContent);
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
How the application knows whether the machine is Laptop or Desktop or Hand Held...I have tried win32_SystemEnclosure by using WMI but I'm getting the wrong info ie, what I'm expecting is not the one...
Is there any api call...Please suggest me or locate where I will get source code asap...
Regards,
nag.
|
|
|
|
|
I'm not sure of anything that is 100% foolproof. In what ways does a laptop differ from a desktop? The presence of a battery is one difference. However, you can have a laptop on AC power without a battery. Can you use Win32_BIOS.TargetOperatingSystem , or the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName registry value, to determine if the device is a handheld or not?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
They don't. Whether a PC called "laptop" or "desktop" is rather arbitrary. OS doesn't care, except for some special OS like "Windows for Pocket PC".
Best,
Jun
|
|
|
|
|
hi gurus,
how to detect the sound input and show this like messenger voice chat?
Thanks.
Ivan Cachicatari Blog[^]
www.latindevelopers.com
-- modified at 10:48 Thursday 13th July, 2006
|
|
|
|
|
Hello,
This may seem like a simple question, but in Visual Studio is it possible to set coding style, specifically:
I like to write like this:
method<br />
{<br />
for<br />
{<br />
statement<br />
}<br />
}
but Visual Studio auto formats it like this (and I hate it!):
method<br />
{<br />
for<br />
{<br />
statement<br />
}<br />
}
How can I set it my way?
-- modified at 10:21 Thursday 13th July, 2006
|
|
|
|
|
your formatting got lost (try <pre> around your code).
if you're asking about bracket indentation, there's a setting in Tools / Options called "Indent braces" that might help
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Hi together,
I tried to compile the fdstream classes from www.josuttis.com with VC6, but didn't succeed. I cut down the code to what doesn't work:
#include <streambuf>
#include <istream>
class mybuf : public std::streambuf
{
protected:
int m_i;
public:
mybuf(int i) : m_i(i) {}
};
class myistream : public std::istream
{
protected:
mybuf buf;
public:
myistream(int i) : std::istream(0), buf(i) {}
};
int main(int argc, char* argv[])
{
myistream strm(5);
return 0;
} On this code I get the following two errors:
error C2512: 'basic_istream<char,struct std::char_traits<char> >' : no appropriate default constructor available
error C2614: 'myistream' : illegal member initialization: 'istream' is not a base or member
I can't figure out what's the problem. It seems std::istream(0) isn't accepted, but I don't know why.
Can anyone help me?
Thank you very much in advance.
Regards,
Marcus.
|
|
|
|
|
khb wrote: error C2512: 'basic_istream<char,struct std::char_traits<char=""> >' : no appropriate default constructor available
std::istream is a typedef for basic_istream<char, char_traits<char> >. basic_istream has the following constructor:
explicit basic_istream(basic_streambuf<Elem, Tr> *_Strbuf, bool _Isstd = false);
Do you really want your streambuf to be null? If so, try casting 0 as follows:
std::istream((std::streambuf*)0);
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Yeah, the streambuf should to be null, as in the original implementation it is replaced by an instance of the inherited streambuffer class using rdbuf() .
However, casting 0 to std::streambuf* results in the same errors.
If you have another idea on how I get the istream constructor called correctly, I would be really happy.
Thank you very much for your help,
Marcus.
|
|
|
|
|
Strange. Not sure why that would be a problem ... I was able to compile your code using g++ with no problems.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
The original author is using VC6.
For the love of god, VS2005 Express is free. Get it.
earl
|
|
|
|
|
I realize that. Generally, GNU is more strick about things like this that Microsoft's compiler.
I have VS2005 Pro ... but it doesn't run on Linux, which is what I have to use at work.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Sorry Zac, I meant to reply to the original author.
VS6 is broken in some ways; I just think that trying to make things work on it is kind of silly when you have a far superior alternative available for free. And the gnu compiler chain is quite nice, but the 3.x series is far superior to VS6 in terms of the probabilty of standard-conforming code compiling and working.
earl
|
|
|
|
|
earl wrote: And the gnu compiler chain is quite nice, but the 3.x series is far superior to VS6 in terms of the probabilty of standard-conforming code compiling and working.
Agreed. But sadly, there are many companies that still do all their development in VS6.
If the OP hasn't already done so, he might want to download the fixed STL from Dinkumware's site (they are the ones that wrote the version that ships with VS). There were several bugs that were fixed, not sure if this might be one of them.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Unfortunately, I have to stick to VS6. It's really bad that the behavior might come from bugs in the STL Can I simply replace the problematic STL classes? If so, can you provide the Link to the Dinkumware's site?
Thank you for you discussion. That brought some light into the dark. I already started thinking that I'm getting to old for understanding C++ Therefore I like your slogan, Zac!
Regards,
Marcus.
|
|
|
|
|
I think Microsoft has a link in MSDN for a service pack download that does it. But here is Dinkumware's site: http://www.dinkumware.com/.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks a million!
Regards,
Marcus.
|
|
|
|
|
Marcus,
There is simply quite a bit of valid code that the VS6 compiler is unable to compile. This in turn limits the quality of the STL that can be provided for it. At the end of the day, it's an 8 year old compiler that was written before the C++ standard was finalized IIRC.
earl
|
|
|
|
|
Hi,
In my project i have to initially display the data from database and also i have to provide the facility to the user to change the value. I have done it in onitdialog message handler where the recordset operations have already handled.
i compiled it successfully but while running i got the assertion saying that
assertion in .exe file
File:afxcmn.inl
line:375
plz help me.
Thanks in advance.
tejaswini
|
|
|
|
|
Can you please make it a little more clear what exactly you did in OnInitDialog() ?
|
|
|
|