|
you want to replace the actual "tab" character with the "visual" representation of the tab ?
for example what would happen if the tab is visually represented by 2 spaces or by 3 spaces ?
Watched code never compiles.
|
|
|
|
|
|
so, just replace (CString::Replace) the "\t" with " ".
Watched code never compiles.
|
|
|
|
|
What should I do for newline?
|
|
|
|
|
It make no sense to "execute" a newline inside a string! Inside a string you could put printable characters, like 'a', 'b', 'c' and so on, and/or control characters, like '\t' (i.e. TAB), '\n' (i.e. LF) and so on.
If you pass such a string to functions like printf , that functions will print-out the printable characters and do what the control characters ask for, for example:
printf("first>\tthis is a sentence...\nsecond>\tthis is another sentence...")
will produce an output on screen similar to the following:
first> this is a sentence...
second> this is another sentence...
as you can see TAB (\t) is not simply expanded to a certain number of characters, but it make the text formatted in columns; the LF instead instruct the printf function to move to the beginning of the next line and place the remaining text there.
Then:
- if you like it, you can replace the TABs expanding them to a fixed number of spaces (supposed that you have a
CString named str , you have only to call str.Replace(_T("\t"), _T(" ")); on it); be aware that usually this is not the behaviour of TAB that the rest of the world is expecting. - absolutely it make no sense to replace the \n characters in a string with newline because in strings \n has the meaning of newline!
|
|
|
|
|
|
Hi Friends,
I am presently doing a project in VC++(VS 2008). it having more than 40 dialog's. for that dialogs i'm designing with controls... it is difficult me to maintain the dialogs good and perfect without missing the alignment's...
so please tell me some tips about designing and how to design the dialogs effectively...
Thanks in advance... Rose ...
|
|
|
|
|
|
|
rp_suman wrote: To make sure if the controls are aligned correctly, you can take a snapshot, paste in MS Paint, draw a line, zoom and check the pixels.
If you really like to work, and like spending your customers cash, that may be a good alternative to simply use the alignment tools in the Format | Align sub-menu in the resource editor.
|
|
|
|
|
|
Hi,
I need to update a code that was written a long time ago, and have some problem.
my question is as follow.
I have a Base class with function f1 that do something.
the Derived class ovveride function f1 and do other thing.
now I need to add to the derived class a function f2 that do exactly what Base::f1() is doing.
and I dont want to duplicate the code (of course)
is it OK to do:
void Derived::f2()
{
Base::f1();
}
or is there a better way to call the f1 from the base class?
Many thanks,
|
|
|
|
|
lune12 wrote: Base::f1();
That's how you should do it.
|
|
|
|
|
You don't actually have to implement a function to call a base class version of a function:
Derived d;
d.base::f();
will call the base class version of f - no virtual function dispatch will happen.
Oh, don't try this the other way around - strange and destructive things will happen
Cheers,
Ash
|
|
|
|
|
Actually there are scenarios where this is useful, like exposing methods from private and protected inheritance. A sort of forwarding.
class Base
{
public:
string name() const;
};
class Derived : protected Base
{
public:
string name() const { return Base::name(); }
};
Edit: The reason being of course to change the access level of a method.
|
|
|
|
|
Just a thought: As someone who prefers composition over inheritance, I can hardly think of a case using protected/private inheritance. Not sure when I used it last time. Also see Stackoverflow[^].
Cheers
/Moak
|
|
|
|
|
It's more likely to be used to open up a protected function in the base class. I've seen that a lot in MFC code and it gives me the willies:
class base
{
protected:
virtual void a();
};
class derived : public base
{
public:
virtual void b()
{
a();
}
};
You can also do it using using declarations but that's scary as well.
Cheers,
Ash
|
|
|
|
|
Begs for a redesign/refactoring of the interface, if you ask me.
|
|
|
|
|
I have actually never inherited in any other way than public as far as I can recall, but elevating the access level of a function does not need protected or private inheritance though.
|
|
|
|
|
In this case I'd almost certainly rewrite the base class to provide what I want than hack the derived class. I know there are social reasons why it may be preferable to forward calls like that but it leaves a bad taste in my mouth.
Actually the real bad taste is implementation inheritance but in the world of GUI frameworks people are very stuck in the early 90s.
Cheers,
Ash
|
|
|
|
|
Unfortunately, far from all classes can be rewritten (for several reasons other than social)
I have used this for access level elevation a couple of times (probably more than two) in about 17 years, so it's not really common, but I believe there is a use for it.
There are of course also other reasons to implement a method in terms of the base class implementation. Code generation tools does it all the time. Mostly along with ToDo comments.
|
|
|
|
|
The only time you can't rewrite a base class is when you haven't got the code for it. The rest of the reasons are all social.
Just out of interest anything you can do with inheritance (of concrete base classes) in the context of code generation you could a lot more cleanly do with composition. MFC, as one example, wouldn't be such a mess of deriving from concrete classes if they'd have done that. However there wasn't the C++ expertise around in 1991 that there is now so you can't blame them in hindsight.
Cheers,
Ash
|
|
|
|
|
I think the social bit got lost in translation. I was looking upon social as political, and not economical, which I assume now you include in social?
|
|
|
|
|
I tend to include economic reasons as social, although as a supposed engineer perhaps I shouldn't.
Cheers,
Ash
|
|
|
|
|
In MFC application, I want to play audio and video file on my dialog. Audio/video file like mp3,vob,wav,flv,wma,dat,avi etc
Is there any example available
|
|
|
|