|
hi friends
can anyone explain me the difference b/w Copy constructor & Assignment operator.
when each of them are invoked.
when we need to overload an assignment operator ?.
please explain with an example C++ program
thanks and regards
prashant
|
|
|
|
|
I suggest you see www.cplusplus.com about Copy constructor and overload operator on that site you can find example.
|
|
|
|
|
a copy constructor is a constructor, ie. it constructs a new object.
the operator= works on an existing object...
CMyObj obj1();
CMyObj obj2 = obj1;
CMyObj obj3;
obj3 = obj2;
|
|
|
|
|
hi all
Is it possible to compile UTF-8 build in visual cpp or is it neccessary to convert it to UTF-16?
if it is possible do let me know ho it is possible.
thanks in advance
|
|
|
|
|
The project option "Character Set" could be what you are looking for.
There are three settings avaiable:
- Use Multi-Byte Character Set
- Use Unicode Character Set
- not set
This option can be set in the project configuration->General.
|
|
|
|
|
puneet_cha wrote: compile UTF-8 build in visual cpp or is it neccessary to convert it to UTF-16?
Neither option is available.
The "Unicode" option was put in place back when "Unicode" was only 16-bits and did not use surrogate pairs or groups. The term UCS-2 is probably closer to Windows "Unicode" or the compiler "Unicode" option.
UTF-16 has 16-bit code units but can use surrogate pairs to represent unicode code points that require more than 16-bits to represent them. Windows "Unicode" is simply 16-bits for every code point, no more, no less.
UCS-2 and UTF-16 map the same but the code units that are used to represent the first part of a surrogate grouping in UTF-16 are ignored in UCS-2.
However, UCS-2 and UTF-16 as well as the term "Unicode" are still mistakenly used interchangeably which causes some confusion.
|
|
|
|
|
bob16972 wrote: Neither option is available.
Or is it?
I got to thinking, and I've not checked VC++ 2005 or beyond. Do they still use "MBCS" and "UNICODE" for compiler options or have they finally started using encoding terms to describe the options.
Does VC++ 2005 or beyond use "UTF-16" and "UTF-8" instead of "MBCS" and "UNICODE" for the compiler options.
I came across a blog stating that Windows XP and above started supporting surrogates so it could be officially called UTF-16 on those operating systems. However, this would conflict with the wide character nature of BSTR and wide chars so I'm guessing the surrogates would still be illegal code units.
Anyone have any info?
|
|
|
|
|
UTF-8 is not supported natively in Windows. Your choices are MBCS or UTF-16 ("Unicode"). You'll need to convert your strings to UTF-8 manually whenever you need UTF-8.
|
|
|
|
|
This has got to be an easy question, but I can't find a place to start.
I want to give a command inside my code.
The problem is when the path has a space in it like c:\Program Files\...
I wanted to use
system(buff) where
buff = "c:\Program Files\myDir\myProg"
This works fine for paths without spaces, but there is something to replace it for paths with spaces.
I just can't remember what it is.
Thanks,
Ilan
|
|
|
|
|
IlanTal wrote: The problem is when the path has a space in it like c:\Program Files\...
put quote( " ) before and after the file path like..
"c:\Program Files\Windows Media Player\wmplayer.exe"
|
|
|
|
|
Thanks for the answer Nave.
That is exactly what I tried.
To my disappointment, it doesn't work for the system command.
Apparently the system command is too old?
|
|
|
|
|
Did you try the ShellExecute() function
ShellExecute( NULL, _T("open"), _T("C:\\Program Files\\Internet Explorer\\iexplore.exe "), NULL, NULL, SW_SHOW );
|
|
|
|
|
Thanks again Nave.
No I didn't and that is exactly the answer I am looking for.
I knew there was something which replaces system, but I couldn't remember what it was.
I will try ShellExecute immediately.
Ilan
|
|
|
|
|
By the time i tried the system command for path having space and it is working. Please check you specified the parameter as below
char *pPath = "\"C:\\Program Files\\Internet Explorer\\iexplore.exe\"";<br />
system( pPath );
|
|
|
|
|
Really? Unbelievable!
Maybe the problem is that I'm giving an input and an output filename as parameters?
If I do it at a command prompt with quotes, all works perfectly OK.
If I do it by using system - on exactly the same string, it does nothing.
I tried even moving the quotes to the directory with spaces, but it made no difference.
c:"a b c"\dcmdjpeg C:\ic2006\dicom\kressel\study1\ctseries\view0405.dcm c:"a b c"\jpegUncompress.dcm
I made a directory "a b c" just for test purposes. In this case I forgot the backslash "c:\a b c", but that isn't the problem.
Could you do me a favor and see if system works if you pass parameters?
For me it works fine so long as I don't both spaces in the path and spaces to separate parameters.
Thanks,
Ilan
|
|
|
|
|
Can you tell me which command are you trying to execute using the system?
|
|
|
|
|
It is an exe file which I received to decompress JPEG Dicom files.
I'm sure the problem exists for any command which has parameters on the command line.
Again it worked just fine until I tried using a path which included "Program Files".
Maybe I should try to run notepad with an input file and see if notepad opens the file.
I'll try something like ""c:\a b c\notepad" myfile.txt"
First I'll try c:\ilan\notepad myfile.txt, since that should work.
|
|
|
|
|
IlanTal wrote: I'll try something like ""c:\a b c\notepad" myfile.txt"
in this case you should specify like
system( "notepad.exe \"C:\\a b c\\myfile.txt"" );
note that \ " are all special character, when you want to insert a quote(") in a string u have to place a \ infront of it.
suppose you hard code "abcd" in the code and passed to the system, then the function will get abcd
you have to specify like "\"abcd\"" for the system() for it to get a string like "abcd"
|
|
|
|
|
Nave, thanks for all your kind help.
It has been very useful indeed!
Apparently it is a combination of system together with that particular exe I'm using.
The exe has to parse the command line to get the input and output files and it has a subtle bug.
All my experiments of using notepad worked fine. (I copied notepad into a b c for test purposes.)
On the other hand that exe fails using the system command.
If I take the buffer which I pass to system and copy it into a command box, all works fine!
I think it is time to use ShellExecute as you originally suggested.
The experiments have been fun, but the system command with that exe doing parsing don't seem to work.
Ilan
|
|
|
|
|
Nave,
I just wanted to let you know what a joy the ShellExecute is.
I used c:\a b c\ as the default directory and I separated out the command from the parameters.
In system it was all one big mess and the exe file got confused.
With ShellExecute everything works like a charm.
Thanks again for your generous help,
Ilan
|
|
|
|
|
IlanTal wrote: Thanks again for your generous help,
You are welcome.
|
|
|
|
|
I've run into a new problem.
ShellExecute launches the program and then returns.
I need the results of the program so I need to know when the program is finished.
It turns out that system() returns only after the program has finished.
Is there any obvious way to know the program has finished?
Thanks,
Ilan
|
|
|
|
|
in that case use the ShellExecuteEx() function. in that function you will get the handle of the new process. so after calling the ShellExecuteEx() function wait for the handle using the WaitForSingleObject() function.
|
|
|
|
|
Once again, thanks for your help.
When I ran things under the debugger, I looked at the directories, saw what files there were, saw how they were created, and I was happy that everything was working.
When I let it go, I realized I still had a problem.
Your help has been extremely useful.
Ilan
|
|
|
|
|
My application is up and running at full speed.
Thanks again,
Ilan
|
|
|
|