|
The way the comma operator works is that it returns the last value. For instance:
int a = 1, 2, 3;
will result in a being 3. So your
return a,b,c;
is really equivalent to:
return c;
|
|
|
|
|
If so, what is the use of the comma operator? Is there real use for it?
|
|
|
|
|
for example it's used in the for statement.
for ( i = 0, j = 0;; i<100; i++, j++)
{
}
or in variable declarations:
int i, j;
and maybe many other places.
This signature was proudly tested on animals.
|
|
|
|
|
It can be overloaded. See Boost Assign[^] library for example:
vector<int> v;
v += 1,2,3,4,5,6,7,8,9;
|
|
|
|
|
Oh yes, comma is used in for loops. It's so common! I didn't realize it!
Thanks!
|
|
|
|
|
The comma operator evaluates bot operands, and evaluates to the result of the second one.
So the first operand is evaluated only for its side effects. One common use is:
<br />
while ( (c=getnextthingie(), c!=EOF) )<br />
{<br />
}<br />
here, the first operand has the side effect of calling getnextthingie and assigning the result to c. c!=EOF is evaluated as loop condition.
Personally, I love the idea that Raymond spends his nights posting bad regexs to mailing lists under the pseudonym of Jane Smith. He'd be like a super hero, only more nerdy and less useful. [Trevel] | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server
|
|
|
|
|
uus831 wrote: Can anyone explain what is actually happening in the code above, and why it is even possible to compile such a code? what does return a,b,c actually implies?
See here and here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Er, yeah, if you COULD declare your function as:
int, int, int Test(int a, int b, int c);
You might get 12 bytes on the stack for your return values, but C isnt made this way!
If you realy want to wedge more values into the 32 bits you are given you could cast say a short and two chars into an int.
return (x << 16 + y << 8 + z);
for example, and then pull it apart in the calling code.
Morality is indistinguishable from social proscription
|
|
|
|
|
I am using main "standard" property sheets for tabbed application.
I would like to have another property sheet embedded in the main tab(s).
I got as far as using CStatic variable in the page, but now I am stuck.
I tried this (snippet)
position = pDoc->GetFirstViewPosition();
COpenHRView *pOpenHR = (COpenHRView*) pDoc->GetNextView(position);
if(pOpenHR->m_pPropFrame1);
{
m_sstv.Detach(); // added this when Attach asserted – no go asserts
m_sstv.Attach(pOpenHR->m_pPropFrame1->GetSafeHwnd()); // asserts– attach only once
}
return CpropertyPage::OnSetActive();
Thanks for reading. Any constructive help as always is appreciated.
|
|
|
|
|
Hey guys, i am trying to test one of my classes using cppunit.
the class is suppose to extract data out of a certain text file and then displays it...
Code:
void readNasdaq::Nasdaq(fstream& myfile)
{
string templine ;
string line;
while (getline (myfile,templine) )
{
line.append(templine);
}
int NasdaqValueID = line.find ("id=\"yfs_l10_^ixic\">" , 0) ;
int NasdaqValueCount = line.find ("</span></td><td class=\"ticker_down\"><span class=\"streaming-datum\" id=\"yfs_c10_^ixic\">" , 0) ;
int LocationNasdaqValue = NasdaqValueID + 19 ;
int LengthOfNasdaqValue = NasdaqValueCount - LocationNasdaqValue ;
string NasdaqValue = line.substr( LocationNasdaqValue , LengthOfNasdaqValue ) ;
cout << " " << endl ;
cout << "The Value Index of Nasdaq is " << NasdaqValue << endl ;
int NasdaqValueChangeID = line.find ("id=\"yfs_c10_^ixic\">" , 0 ) ;
int NasdaqValueChangeCount = line.find ("</span></td><td class=\"right_cell ticker_down\"><span class=\"streaming-datum\" id=\"yfs_pp0_^ixic\">" , 0) ;
int LocationNasdaqValueChange = NasdaqValueChangeID + 19 ;
int LengthOfNasdaqValueChange = NasdaqValueChangeCount - LocationNasdaqValueChange ;
string NasdaqValueChange = line.substr (LocationNasdaqValueChange , LengthOfNasdaqValueChange ) ;
cout << "The Value Change for Nasdaq is " << NasdaqValueChange << endl ;
the problem i have with my cppunit is how am i suppose to read the value being outputted and test it...
Code:
#include "financetest.h"
#include "finance.h"
CPPUNIT_TEST_SUITE_REGISTRATION (FinanceTest);
void FinanceTest::setUp()
{
New = " ";
NewValue = " " ;
}
void FinanceTest::tearDown()
{
}
void FinanceTest::testEquals()
{
}
How can i continue from here.. really need some help from this
|
|
|
|
|
I know it's early, but I'm not seeing what readNasdaq::Nasdaq() has to do with your question.
As I understand it, CppUnit is a framework for creating unit tests in C++. What does this have to do with extracting data out of a text file and displaying it?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Sorry, what i meant was to show my class and how it get the information i want to be displayed. I got to use cppunit to test this class to show that it is extracting the right information.
For example, if the class extracts "a" , i will have to compare it to the cppunit test and see if it has the same value also.
The problem i am facing is how do i do a test based on the output.
|
|
|
|
|
Hallo,
I use a tabbed Dialog, which shows several Dialogs in it. The tabbed Dialog is resized to the size of its MDI Window.
The problem is, that if the MDI Window is resized to a smaller size then the dialog in the tabbed control, the dialog in the tabbed control is not shown completely.
So I want to know not the window rect of the dialog in the tabbed dialog, but the size of my form template, which I designed in the form editor of Visual C++ 6
So my main question is:
Is it possible to get the height and with of my form as it is in the editor, so to speak the size of my, for example, IDD_MAIN_DIALOG resource my CDialog derived class?
Thank you for your help!
|
|
|
|
|
use GetWindowRect() function to get rectangle for the dialog box and then a simple math will solve your problem
|
|
|
|
|
But the Problem is, that I get the current size of my form with GetWindowRect(). If it has already been scaled to small, some of the form controls will not be shown...I need the height and width of my Form as I see it in the form Editor...
|
|
|
|
|
One way I could think is store your original dialog rectangle in some variable and use those values in InitDialog() Function. The other dirty way, you can check the the dialog box co-ordinates in .rc file. and set the Dialogbox rectangle to those value in InitDilaog fuction().
HTH
|
|
|
|
|
|
Hi All,
How to convert a char array into CString? I have one array like this
char charr[1000];
....
drwFile.Read(charr,656); //reading some characters from the file
CString str;
how to store the charr array in to str?
Regards,
Kumar
|
|
|
|
|
The easy answer is: you don't have to convert, just assign it. But it depends on your UNICODE setting. I suggest you read this article[^] to get a better understanding on character encodings. This will help you a lot in the future.
|
|
|
|
|
Thanks Cedric! The given article is very help full
Can't we convert the char array like this?
Cstring str(charr); //charr is char array
Regards,
Kumar
|
|
|
|
|
Yes, the CString constructor is overloaded to accept that.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
As I said in my previous reply, it all depends on your UNICODE setting.
BTW, why don't you just check ? It's one line of code and you can easily verify if it compiles or not. If UNICODE is turned on, the code won't compile.
|
|
|
|
|
Nope. It will work. CString constructor automatically handles the conversion,
see [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Just be carefull, your char array has to be null-terminated to be used to initialize a CString like that or even if you use the = operator ( CString str; str = charr; ). Othwerwise it will keep on reading characters till it finds a null character somewhere after your array and which either results in access violation OR you get garbage in your str.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
I have client and server . hundred of client connect to the server . and I am serving the data to the client
but not every client is getting data . why it is happening . I think this is due to winsock internal buffer
is there way to increase winsock internal buffer . i am using TCP/IP socket
Trioum
|
|
|
|