|
#include <iostream>
#include <vector>
#include <cmath>
int main (void)
{
std::vector<int> MyVect;
int a= -5;
int b= abs(a);
return 0;
}
<b>Maxwell Chen</b>
|
|
|
|
|
Hi !
I just realised my previous message was wrong, the '<' disappeared !
What I'd like to know is why abs is not in the std namespace ?
Jerome
|
|
|
|
|
If my understanding is correct, namespace std wraps those standard classes of the Standard C++ Library (for example, iostream, string, list, map, etc.)
Function abs(...), and all the rest functions like printf(...), are inherited from the C Language Runtime Library. They are of the global namespace. To invoke them, do this way...
::abs(nMyValue);
which means abs(...) belongs to the global namespace.
Maxwell Chen
|
|
|
|
|
At a guess, you're still using Visual C++ 6.0. VC 6's supplied library did not do the <cxxx> headers properly: while they included the old functions, they didn't put them in the std namespace.
By my reading, this was fixed in VS.NET 2002.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Exactly, I'm still using VC 6 !
Thanks for your answer !
Jerome
|
|
|
|
|
Hi All.
I need help related to files. I have a binary file...let say abc.bin. If i open this file with notepad, the content is something like as follows...
5b 7a 82 43 2c 03 b0 12 02 a6 0c 93 03 24 b0 12
24 a0 02 3c b0 12 0e a1 92 43 2c 03 e2 93 17 12
And so on...
Now, I want to convert that file to a file that have contents as
0x5b 0x7a 0x82 0x43 0x2c 0x03 0xb0 0x12 0x02 0xa6 0x0c 0x93 0x03 0x24 0xb0 0x12
0x24 0xa0 0x02 0x3c 0xb0 0x12 0x0e 0xa1 0x92 0x43 0x2c 0x03 0xe2 0x93 0x17 0x12
And so on...
I am trying to use CFile to open and then modifying it, but not able to do.
If anyone can suggest anything that can resolve my issue, it will be really great for me.
Thanks and Regards,
Pankaj Bhalla
pankajbhalla@mantraonline.com
|
|
|
|
|
You mean you want to read in each line, and for each hex value, prefix it with '0x'. You'll need to read from one file, write to another, and then delete the original, and rename your output file. Doing this in place is awkward because you are changing the size of the file.
Hope that helps a bit.
Steve S
|
|
|
|
|
why using 2 different files ?
we can add bytes into a file without overwrite it. an we can move into the file stream...
TOXCCT >>> GEII power
|
|
|
|
|
Using what functions? Anyway, even if those functions existed, the excessive IO to support such a function would vastly dwarf the extra code to create a new file and rename it.
Also, there are other issues involved. What if the program failed halfway through. Now you have a partially converted file which is totally worthless. This is a major concern for real life applications. Either the operation completes successfully or it fails without damaging the original.
BTW, we are converting 1 binary bytes to 10 ASCII bytes. We are doing a lot more than just inserting two characters.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I'm developing a client server application using MFC. My server should be able to accept multiple connection from clients (50 clients). I have a problem when I connect two clients, either one of the client will be disconnected. What is the cause of the problem. I'm really stuck and need help on solving the problem.
Here is my server code that accept client connection:
UINT thread(LPVOID p)
{
char recv_msg[3];
CSize size;
size.cx=0;
size.cy=30;
int s,loop,flag=0;
int msgcount;
CVCBUILD2000Dlg *dlg=(CVCBUILD2000Dlg*)AfxGetApp()->GetMainWnd();
msgcount=dlg->getcount();
msgcount = 1;
if (msgcount==-1)
loop=0;
if(loop)
{
dlg->msgsock[msgcount]=accept(dlg->sock,(sockaddr*)&(dlg->serv),&(dlg->addlen));
s=1;
AfxBeginThread(thread,0);
dlg->SetForegroundWindow();
dlg->m_list.InsertItem(dlg->count++,"Connected");
dlg->m_list.InsertItem(dlg->count++,inet_ntoa(dlg->serv.sin_addr));
dlg->m_list.Scroll(size);
dlg->m_button.EnableWindow(TRUE);
//while ERROR_SOCKET not true
while (s!=-1)
{
//get the input from connected PDA
s=recv(dlg->msgsock[msgcount],recv_msg,5,0);
dlg->m_Status.SetWindowText("");
dlg->ChkInput(recv_msg[0], recv_msg[1]);
if (recv_msg[0] == 'F')
{
s = -1;
}
dlg->SetForegroundWindow();
dlg->m_list.Scroll(size);
}
dlg->msgsock[msgcount]=NULL;
for (int i=0;i<3;i++)
if (dlg->msgsock[i]!=NULL)
flag=1;
if (flag != 1)
{
dlg->m_button.EnableWindow(FALSE);
//this calls the function ClearWindow
//pass 1 param (msgsock)
dlg->ClearWindow(msgcount);
closesocket(dlg->msgsock[msgcount]);
dlg->m_list.InsertItem(dlg->count++,"Disconnected");
dlg->m_edit.SetWindowText("");
}
}
AfxEndThread(0);
return 0;
}
|
|
|
|
|
I really don't understand your code. I think you have major design issues to deal with. Mixing the socket handling code up with the protocol handling code with the windows handling code seems to me to be a recipe for problems. And a thread per connection is usually inefficient. Consider using either MFC sockets, straightforward sockets with Windows Messages for events, or sockets with Events you can 'WaitForMultipleEvents' on. Also reference some of the server library implementations available here. I have one of my own, but it's not documented yet. Here if you're interested.
Anyway I suspect your problem is that 'msgcount' never seems to be set in the 'dlg'. And there's clearly a bug here,
msgcount=dlg->getcount();
msgcount = 1;
Good luck.
Paul
|
|
|
|
|
Sir,
I am developing an which maps CString as the key and maps to the class.
For that I am using this code.
in Person.h"
CPerson {
private:
int age;
public:
CPerson ();
CPerson (int a){
age = a;
}
}
And in "FileView.cpp"
CMapStringToOb map;
CPerson one ;
//one = new CPreson();
map.SetAt( "Bart", one );
This gives me an error.
Pls help me with a solution .
Regards
|
|
|
|
|
use std::map instead. Then you can do this:
myCoolMap["Bart"] = one;
I suspect the problem though is that your class needs a copy constructor and/or operator = in order for this to work.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Either use the template version of CMap (e.g. CMap<CString, LPCTSTR, CPerson*, CPerson*> ) in afxtempl.h , or derive CPerson from CObject .
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
First,how can i choose the particular thread which i want to read since there are more than 13000 thread in this forum? Is that any search engine to perform this task?
Second, in the mulitple document application (MFC)project,is there possible to do all this thing as below:
my main task is plotting the different graph at different window from different array , for example array a[] at window:1,array b[]at window:2.
After i open the new window by click the command at New Window at menu in the mainframe ,is that possible to use the same button which in placed at the cformview ,to plot the graph ? How can place the different code in the same button?The case is like this after i compile and built the project:
There is the button named "plot" at the first window(window:1).
The code in the button "plot" is the function to plot array a[];
Then, i open the new window which is window:2, how can i use the same button to plot the array b[]?
Thank you.
|
|
|
|
|
tcsiong wrote:
First,how can i choose the particular thread which i want to read since there are more than 13000 thread in this forum? Is that any search engine to perform this task?
search comments[^]
It's not a bug, it's an undocumented feature. suhredayan@omniquad.com
messenger :suhredayan@hotmail.com
|
|
|
|
|
Hello,
I need to embed any number of binary files (i.e. Word, Excel, etc) into my CDocument. These may then be extracted to disk and the executed so that the appropriate program is launched.
I have searched the Internet and found no ideas on how to do this. Any suggestions?
Ted
|
|
|
|
|
Consider basing your document type on COleDocument , then storing your own items using classes derived from CDocItem .
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Do they have to be legal ip addresses?
And since an ip address can be represented by a single 32bit number wouldn't rand() work?
Here is one structure that windows uses to store ip addresses you can find it in the MSDN help:
struct in_addr {
union {
struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
struct { u_short s_w1,s_w2; } S_un_w;
u_long S_addr;
} S_un;
};
So the code is simple:
in_addr address;
address.S_addr = rand();
John
|
|
|
|
|
All you have to do is generate a number between 0 and 255, once for each octet.
unsigned char s[16];
sprintf(s, "%u.%u.%u.%u",
rand() % 256,
rand() % 256,
rand() % 256,
rand() % 256);
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
if you need it into a bind() call, use ADDR_ANY.
TOXCCT >>> GEII power
|
|
|
|
|
I think I'd want to know why.
Is there a legitimate reason for doing this?
Paul
|
|
|
|
|
hello everybody... using vc6/MFC how can i grab highlighted (selected) text from the current screen? Sorta like firing up a spell checker from the task bar to fetch selected word(s). All helpful suggestions appreciated! Thanks!
tom
|
|
|
|
|
This is from the PushSource filter example for DirectShow:
int cbFileHeader = sizeof(BITMAPFILEHEADER);
// Store the size of the BITMAPINFO
BITMAPFILEHEADER *pBm = (BITMAPFILEHEADER*)m_pFile;
m_cbBitmapInfo = pBm->bfOffBits - cbFileHeader;
I'm not quite sure why "bfOffbits - cbFileHeader" is done.. bfOffbits tells you where the actual picture information starts right? So if you subtracted that offset by the header wouldn't you end up with 0?
|
|
|
|
|
When you set a breakpoint on the m_cbBitmapInfo = pBm->bfOffBits - cbFileHeader statement, what are the values of the three variables? In some test code that I had lying around, the value of bfOffBits was 54, so subtracting 14 from that yielded 40.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|