|
shiroze wrote: how do i read an input file that contains integer and , load the values in the files into my binary search tree in c++
ur help will b appreciated
Are you using the standard C++ library? If so, look at this page for reading from a file[^].
It has an example of opening a file in binary mode and reading data from it, placing it into an array.
Once you have read all of the integers into an array, you can loop through the array inserting each integer into your binary tree.
|
|
|
|
|
If you want to read and write to a file you can use of CFile class.
|
|
|
|
|
in fact, use fstream is better than CFILE
|
|
|
|
|
can somebody help me with codes on how to create an empty binary search tree, read an input file that contains integer using an eof loop, load values in the files into my binary search tree in c++
|
|
|
|
|
|
Plenty of folks here will be more than glad to ASSIST you. Which part are you having trouble with (hint: "All of it" is not an acceptable response)?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hello ,everybody!
i like thiking! give some think with a software or web site.for example : you can tell me which sort with soft or web site! thanks!
|
|
|
|
|
Im sorry but I dont understand what you said?
|
|
|
|
|
i want to you tell me some idea about software. for example :which sort(idiographic function) about a soft !
because i want to developed the software . Have you any good idea?
|
|
|
|
|
A good choice for a first program is to write a calculator.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
lgbean wrote: ...i want to developed the software . Have you any good idea?
Yes. Start with a spell/grammar checker. You'll get instant gratification from it.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello everyone,
I met with a strange issue that derived class function can not access base class's protected member. Do you know why?
Here is the error message and code.
<br />
error C2248: 'base::~base' : cannot access protected member declared in class 'base'<br />
<br />
class base<br />
{<br />
protected:<br />
~base() {}<br />
private:<br />
void foo()<br />
{<br />
base* b = new base;<br />
delete b;<br />
}<br />
};<br />
<br />
class derived : public base<br />
{<br />
public:<br />
~derived() {}<br />
private:<br />
void goo()<br />
{<br />
base* b = new derived;<br />
delete b;
}<br />
};<br />
thanks in advance,
George
|
|
|
|
|
The base destructor is protected.
I guess it seems logical that if derived derives from base then it
should have access to the protected destructor but it doesn't work
that way.
You can fix it by making the base destructor public, making
derived a friend of base, etc.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark,
Do you think destructor has something special or there is something wrong with my code? I think derived class should be able to access protected member of base class, right?
regards,
George
|
|
|
|
|
Which compiler are you using ? If it is VC6, then it is a known bug of the compiler itself. If you compile this code under VC2003 or VC2005 this should just work.
|
|
|
|
|
Hi Cedric,
I am using Visual Studio 2005. I do not think there is a bug, and I think there should be something wrong with my code. How do you think of it?
regards,
George
|
|
|
|
|
It doesn't work on 2005 or 2008 either.
I'm going to ask MS about this. I honestly don't know why it
doesn't compile. Intuition talls me it should work but it's probably
one of the many things I don't know about C++
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ok, thanks to a Fellow MVP, I got some answers.
It's not a VC bug.
The behavior is also the same on VC 2008 (I tested that).
void goo()
{
base* b = new derived;
delete b; // error in this line C2248: 'base::~base' : cannot access protected member declared in class 'base'
}
The problem is, even though you're in a class publicly derived from base, the
compiler only knows it's dealing with a base object ("b") so you don't
have access to any private or protected members of b. Only when the object is
of type derived does the compiler know that the base class protected members are
accessible from derived.
If, in the above code, b was a "derived" object, you'd have no problem.
To fix it, you can:
a) Make the base destructor public.
b) Make derived a friend of base.
c) In Goo(), create a derived object instead of a base object.
Each method has pros and cons, depending on what you need for your implementation.
I'm not sure why you have the base destructor protected. If you are trying to prevent
base objects from being created, then you should probably have a protected (or private)
default constructor as well, so creating a base object will fail to compile as well.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark!
Your reply is so comprehensive and great! I have tried and it works.
regards,
George
|
|
|
|
|
I created a simple windows socket program, it acts as a client only that sends data to specific server application. When I tried to send the message, I noticed in the receiving application that the series of data is accumulated altogether in one message only. I intended to send the data to be one by one.
Please help, thanks a lot.
Jers
|
|
|
|
|
If you are using synchronous sockets (so, using send and recv functions), there is no notion of packets there. You just read a certain amount of bytes. If you want to keep packets, you will need to send first the size of the packet. On the other side, you simply read this data (coded on 1,2 or 4 bytes depending on your needs) and then read the corresponding number of bytes.
|
|
|
|
|
|
Hi
In a dialog I have 3 edit boxes, and a button,
After Clicking on this button I want to know that: which edit box had focus?
Is there any way?
Thanks
|
|
|
|
|
when you click button then button has focus,can you use of GetFocus ?
|
|
|
|
|
When you click the button the button will receive a WM_SETFOCUS message.
That message contains the handle of the window that lost focus. You could compare
that handle to the edit control window handles.
An alternative is to have the edit controls track when they get focus.
Remember that the last window with focus when your button is clicked isn't necessarily
going to be one of the edit controls. It may not even be a window in your app.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|