|
Hi,
If you mean the const_cast casting operator, I believe you have used it wrong. It should be used like this:
char* pszMsg = const_cast<char*>(sstrMsg.str().c_str());
This shouldn't give any problems.
codito ergo sum
|
|
|
|
|
Hello,
I used it just like you said it should be used. It's just that the '<' and the '>' 'disappeared' because I didn't use '<' and '>' respectively. Sometimes the parser for the message removes those in pre tags and sometimes it doesn't.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Your code looks very dangerous.
Q1) Why would you need to cast away the constancy of the pointer returned by c_str() ?
How about using: const char* pszMsg = sstrMsg.str().c_str();
Q2) Why would a function named SPrintBuffer() need a pointer to a pointer of type char* ?
The name implies that it is just going to print out the contents of the buffer, not modify it.
Note: Modifing the data return via c_str() , is a very bad idea.
INTP
Every thing is relative...
|
|
|
|
|
I know that the code looks very dangerous. I double checked the code for SPrintBuffer() and it doesn't modify the string.
The reason that the reason the function takes just a char* and not a const char* is unknown to me. I need to add a link layer of a protocol to a program that my teacher wrote. Please don't tell me, the entire program is badly designed and all the code looks like spaghetti... If you want to see some obfuscated C code, this program is right for you!
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Sorry I have been gone for a few days.
1) It sounds like your teachers code would not pass a review by me, let alone a quality assurance team.
If the function does not modify the data pointed to by the argument, then you should say so by making it a pointer to constant data.
2) You still should not need to use const_cast , instead you can just call the function like so: SPrintBuffer((char*)str.c_str()); .
Note: The const_cast should not be needed in this particular case.
Note: In your original code you are trying to pass a char** and not a char*
|
|
|
|
|
John R. Shaw wrote: Sorry I have been gone for a few days.
So have I...
John R. Shaw wrote: 1) It sounds like your teachers code would not pass a review by me, let alone a quality assurance team.
That was my first thought and I offered to rewrite the entire program instead of doing all the other assignments. This was a no-go since the course is not going to be given anymore.
Anyway, that's the way we learn things in college these days..
John R. Shaw wrote: 2) You still should not need to use const_cast, instead you can just call the function like so: SPrintBuffer((char*)str.c_str());.
I force myself to use straight C++ only. The C-Style casts are there fore backwards compatibility. They shouldn't make a difference. I'll try it and let you know if there it will work.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Looking for GUI simple tutorial with VC++ .NET version 7.1
I am a newbie in this product. I would like to have a GUI simple tutorial for VC++ version 7 using with MFC (such as click on button then get result of addition of 2 numbers or display a note on edit box. I downloaded 1 sample from www.msoe.edu/eecs, but it for older version then I was stuck in the middle instruction (due to ClassWizard could not be found). I found microsoft VC++ devepment tool is very very hard to learn.
Please advise me a good book about MFC and GUI for beginner.
I am a hardware guy, so I like GUI to interface with devices and instrument.
Thanks.
MilkyWay
MilkyWay
|
|
|
|
|
Loc Milkyway wrote: I found microsoft VC++ devepment tool is very very hard to learn.
Well, C++ is a difficult language and Visual C++ is an intimidating environment! Other languages, such as VB and C# are far easier for doing GUIs.
Anyway, I took a peek at this site and it looks quite good.
http://www.functionx.com/visualc/[^]
If you click on the "Introduction to Applications" link in the top left it takes you into a tutorial in which they occasionally tell you how to do it if you're using VC++ 6 and how to do it in VC++ 7.1. You will also see VC++ 7.1 IDE screenshots in various places.
Instead of ClassWizard you have to use the Class View and Poperties windows. See here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcgrfWhereIsClassWizardInVisualCNET.asp[^]
Kevin
|
|
|
|
|
Kevin ! Thank you... thank you very much. www.functionx.com is the cool site for me.
MilkyWay
|
|
|
|
|
Hi,
I'm currently creating a lot of ownerdrawn MFC-controls. Can anybody tell why i should use DrawItem() instead of OnPaint()?
|
|
|
|
|
for many controls, DrawItem will give you information about the specific sub-item (menu choice, list box item, etc) that you need to draw. OnPaint is for the control as a whole.
for controls that don't have sub-items, there's not much difference between the two (buttons, etc)
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Chris Losinger wrote: for controls that don't have sub-items, there's not much difference between the two (buttons, etc)
For buttons, DrawItem provides provides a lot of info that OnPaint does not, such as selection and focus state, and whether the button is up, down, disabled, ect.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
|
good morning,
anybody has experience with this? the report is txt file, everything looks just fine, but when send it to print, between some pages it would print blank pages, it didn't miss any info, but between 2&3, 3&4, 4&5 it "insert" empty page into. I have check the form feet and everything on txt file, it looks fine.
here is the print job:
if ( nPageNo > 1 )
m_Rpt->rptMessage( "\f" ); // form feed...
m_Rpt->rptMessage( m_strOrientCPI );
//do line drawings, detail headers, etc.
if ( nFirstGrpChg != -1 )
{
checkForNewPage( true );
drawBottomLine();
doDetailSummary();
drawBottomLine();
checkForNewPage( false, nFirstGrpChg );
if ( m_nCurrentPageLine == 0 )
doHeaders();
else
{
//if not a new page, still need a seperator line
fprintf(pf_rptlog,"\n" );
m_nCurrentPageLine++;
}
//call formatData here to correct witdth after footer and headers
strOut = formatData( pszData, delimiter, 0, true );
while( nFirstGrpChg < m_nDrillDownLevels )
{
drawTopLine( ( nFirstGrpChg + 1 ) );
fprintf(pf_rptlog,"%s\n",doBoinks( vholdDataHdr[nFirstGrpChg], (nFirstGrpChg + 1) ).c_str() );
m_nCurrentPageLine++;
nFirstGrpChg++;
}
drawTopLine();
doDetailHeader();
drawMiddleLine();
}
else
{
checkForNewPage( true );
if ( m_nCurrentPageLine == 0 )
{
doHeaders(); //include firstpages stuff in here
nFirstGrpChg = checkGroupHeaders( vholdDataHdr, pszData, delimiter );
loadFormat( m_currentFmt ); //this will set correct with for first grp on first page
strOut = formatData( pszData, delimiter, 0, true );
if ( nFirstGrpChg != -1 )
{
while( nFirstGrpChg < m_nDrillDownLevels )
{
drawTopLine( ( nFirstGrpChg + 1 ) );
fprintf(pf_rptlog,"%s\n",doBoinks( vholdDataHdr[nFirstGrpChg], (nFirstGrpChg + 1) ).c_str() );
m_nCurrentPageLine++;
nFirstGrpChg++;
}
}
drawTopLine();
doDetailHeader();
drawMiddleLine();
}
else
{
strOut = formatData( pszData, delimiter, 0, true );
}
}
m_bFirstGrpLine = false;
if ( m_nFrameGroup != -1 )
{
strOut = doBoinks( strOut ); //getBoink() + strOut + getBoink();
}
fprintf(pf_rptlog,"%s\n",strOut.c_str() );
m_nCurrentPageLine++;
if ( m_nCurrentPageLine == ( m_nPageLength - 1 ) )
doFooter();
|
|
|
|
|
Have anybody seen any examples or source code how to make toolbar for Outlook Express?
|
|
|
|
|
See Demo toolbar for OE
http://www.plugins-soft.com/demos.html
BUT this commercial source.
|
|
|
|
|
Hi I'm trying to do the following:
1) generate a random # from the array layer_array[]
2) swap the number generated with a negative number, to avoid repetition of that random #.
I'm not sure I'm correctly sampling from layer_array[]. And I'm definitely not implementing swap() correctly....how would i proceed?
Please help.
<br />
#include <cmath><br />
#include "stdafx.h"<br />
#include <ctime><br />
#include <cstdlib><br />
#include <algorithm><br />
#include <fstream><br />
#include <iostream><br />
#include <iomanip><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
const int size = 20;<br />
<br />
int layer_array[size]={0};<br />
<br />
for(int i=0; i<size; i++)<br />
layer_array[i]=i+1;<br />
<br />
srand((unsigned)time(0)); <br />
<br />
int random_integer[size] ={0};
<br />
for(int index=0; index<size; index++)<br />
{<br />
random_integer[index] = (rand()%size)+1; <br />
swap(&layer_array[index],&layer_array[index*-1]);
<br />
cout << random_integer[index] << endl; <br />
}<br />
<br />
return 0;<br />
}<br />
|
|
|
|
|
aaadetos wrote:
swap(&layer_array[index], &layer_array[index * -1]);//error c2664
I'm curious what you are expecting to swap with this. You typically don't dereference an array using a negative number.
By the very definition of random, uniqueness is not a quarantee. Therefore, you can't get a random number that is guaranteed to not repeat. If you do, then it is not random. However, if you are simply wanting a list of unique numbers returned to you in a pseudo-random order, that is a different beast altogether.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I'm curious too! According to the code presented, [index * -1] would result in an illegal array index value, except for index=0.
INTP
Every thing is relative...
|
|
|
|
|
you say you have a c2664 compiler error, ,but does it say exactly ?
C2664 is : 'function' : cannot convert parameter number from 'type1' to 'type2'
please tell the entiere error message, ,otherwise it doesn't mean anything for us...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
One way to obtain an array of random numbers with none repeating is as follows:
Since your random number is to be in the range 1-n, it is better to simply initialize an array of size n with the numbers 1-n:
for (int i = 0; i < size; i++)<br />
layer_array[i] = i + 1;
(BTW for peformance, don't initialize the array first with "{0}" since you are immediately initializing it one line later.)
Now, seed the random number and then go through the array again exchanging every value with the value at a randomly selected offset:
for (i = 0; i < size; i++)<br />
{<br />
int dst = rand() % size;<br />
<br />
int tmp = layer_array[i];<br />
layer_array[i] = layer_array[dst];<br />
layer_array[dst] = tmp;<br />
}
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi
I'm not sure what u mean:
(1) to fill an array with non-repeating random numbers
or (2) to shuffle array elements
From your code it looks more like 2. It also looks like the [Delete] was pushed here and there...
The technique of marking used elements is not good. If u had an array of 1M the last iteration would lots of time coz u'd repeat it lots of time till u hit the one out million left..
What u should do is this:
<br />
int i, new_array[size], old_array[size];<br />
<br />
for(i=0; i<size; i++)
init(old_array+i);<br />
<br />
for(i=0; size>0; i++) {<br />
new_array[i] = old_array[x=(rand()%size)];<br />
<br />
old_array[x] = old_array[--size];<br />
}<br />
HTH
Yakov
-- modified at 10:07 Thursday 27th October, 2005
|
|
|
|
|
I am new to the use of sockets, ports and client/server applications.
I have an application that will Connect to a proxy server (to allow for remote commands).
However if the server is temporarily lost (unexpectedly) how do I detect it returning?
My application continues to run but never re-Connects to the server.
Does the server notify me? if so how?
Should I use GetPeerName or can I continually try to Connect to an already connected port
I have a 2 minute timeout timer that I intend to use as a Connect retry control but I need to know when to start.
I am using Visual Studio 6 and VC++
|
|
|
|
|
cgb143 wrote: However if the server is temporarily lost (unexpectedly) how do I detect it returning?
If a socket connection is closed, you need to reinitiate it. On TCP/IP level there is no notification when another peer is back "online" after the connection is closed, you could try to reconnect in intervalls or work out a protocol where the server activly sends something (like a broadcast inside a LAN). Make sure you don't flood the network with wild/endless reconnect attempts, e.g. give up after the 10th reconnect attempt. Hope it helps.
|
|
|
|
|
i'm trying to implement a button that functions for example the way that the seek or pitchbend controls function on a cd player. that is, you press/'push' it and 'work starts getting done' and 'stops getting done' when/after you release the button.
the only way that i know and that works is to check mouse coordinates upon WM_LBUTTONDOWN/UP (since WM_COMMAND gets sent only after you press and depress a button) and compare them with the button position/recantgle and then take appropriate action... but that seems too complicated (calculating, storing & comparing coordinates), is there a simpler way ?
thnx
|
|
|
|