|
i don't know if this is what you are looking for
but my this will help
<br />
DWORD str_num = atoi("12345");<br />
Pain is a weakness living the body
|
|
|
|
|
Didn't work
Actually I have a string like " b7333109 " and I wanna convert it to a dword
|
|
|
|
|
|
I am trying to overload a comparison operator in a templated class and while the class files compile without complaint, the actual comparison statement prompts a C2678 compiler error:
error C2678: binary '>' : no operator found which takes a left-hand operand of type 'mrg::mrgFwdPt<_Ty>' (or there is no acceptable conversion)
with
[
_Ty=double
]
relevant code is
namespace mrg
{
template<class _Ty> class mrgFwdPt
{
public:
mrgFwdPt()
{
}
mrgFwdPt(_Ty v, Date dt) : _mVal(v), _mFwdDt(dt)
{
}
~mrgFwdPt()
{
}
inline void SetValue(_Ty v) { _mValue = v; }
inline void SetDate(Date d) { _mFwdDt = d; }
inline _Ty GetValue(void) { return _mValue; }
inline Date GetFwdDt(void) { return _mFwdDt; }
// these operators work on the date objects to allow
// sorting of the forward points by date
bool operator>(const _Ty& right) const;
private:
_Ty _mVal;
Date _mFwdDt;
};
template<class _Ty> bool mrgFwdPt<_Ty>::operator>(const _Ty& right) const
{
return (_mFwdDt > right._mFwdDt)
}
}
in the main program:
mrgFwdDt<double> one, two;
.
.
.
if (one > two) <- generates the compiler error
FWIW the date comparison operator works correctly and the date class has been used as is for a couple years.
Running MS Visual Studio .Net 2002 (C++ ver 7)
Thx
|
|
|
|
|
Never mind, The parameter passed in the operator declaration and definition were incorrect, should have been classes.
|
|
|
|
|
Hi, I just came up with some quick C++ problems that I thought some people might like to try out. Post your answers as replies. Good luck!
1) Identify any errors in the following declarations.
a. int x[4] = { 8,7,6,4,3 };
b. int x[] = { 8,7,6,4 };
c. const int SIZE = 4;
int x[SIZE];
2) What is wrong with the following piece of code?
int sample_array[10];
for (int index=1; index<=10; index++)
sample_array[index] = 3*index;
3) Suppose we expect the elements of the array a to be ordered so that
a[0] <= a[1] <= a[2] <=…
However, to be safe we want our program to test the array and issue a warning in case it turns out that some elements are out of order. The following code is supposed to output such a warning, but it contains a bug. What is it?
double a[10];
<some code="" to="" fill="" the="" array="" a="" goes="" here.="">
for (int index = 0; index <10; index++)
if(a[index] > a[index +1])
cout <<”Array elements”<
|
|
|
|
|
soer wrote:
1) Identify any errors in the following declarations.
a. int x[4] = { 8,7,6,4,3 };
b. int x[] = { 8,7,6,4 };
c. const int SIZE = 4;
int x[SIZE];
Yes, the array x is being defined 3 different times.
soer wrote:
2) What is wrong with the following piece of code?
int sample_array[10];
You should be using std::vector instead of a static array.
soer wrote:
3) Suppose we expect the elements of the array a to be ordered so that
a[0] <= a[1] <= a[2] <=…
for (int index = 0; index <10; index++)
if(a[index] > a[index +1])
cout <<”Array elements”<<index<<” and”="" <<="" (index="" +1)<<”are="" out="" of="" order.”;<="" i="">
Yes, there is no space between the words and the numbers being printed out.
soer wrote:
4) Consider the following function definition:
Void tripler(int& n)
{
n=3*n;
}
That should be:
n *= 3;
and "Void" should have a lower-case v.
soer wrote:
5) What (if anything) is wrong with the following code? The definition of tripler is given in #11.
int b[5]={1,2,3,4,5};
for (int i=1;i<=5;i++)
tripler(b[i]);
The line containing "tripler" is not indented properly.
soer wrote:
6) Which of the following are acceptable function calls?
too2(my_array, 29);
too2(my_array, 10);
The function name is incorrect. It should be "tutu".
So how did I do?
Sometimes I feel like I'm a USB printer in a parallel universe.
|
|
|
|
|
hehehe
Ant.
|
|
|
|
|
Too easy .
Pain is a weakness living the body
|
|
|
|
|
Syntaxx and code form is not a problem in any of the problems here. Spaces b/w words dont matter nor does indentation. Try again!
|
|
|
|
|
Maybe those problems are concerned with as folloing:
1.Overflow
2.Reference
...
and I can't understand the last problem.
|
|
|
|
|
Using CxImage, I'm loading a PNG from a dll. The png has some transparent parts. When I display the image on the screen, the transparency seems to be ignored. I've looked thru the code but just can't seem to find what I am looking for. Can someone provide a sample or point me in the right direction.
Snip-it of my code from my ::OnPaint() handler (error checking has been removed):
CxImage *image = new CxImage();
HRSRC hres;
hres = FindResource( dll->getModuleHandle(), "#5099"; , "PNG");
image->LoadResource( hres, CXIMAGE_FORMAT_PNG, dll->getModuleHandle());
image->Draw2( dc, 10, 10, 247, 52);
I get the image but the transparent parts are not transparent.
Thanks,
Randy
|
|
|
|
|
Hello,
I need to draw some rectangle which each has a dot in the centre.
The dot representing the x and y cordinates.
Can anyone help.
lvidot
|
|
|
|
|
Check MoveTo and LineTo , FrameRect and
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
How can I do something like TRACE if I'm not using MFC or ATL ?
I want my function that displays complex data structures to be able to show the result somewhere inside the IDE.
//Peter
|
|
|
|
|
VOID OutputDebugString(
LPCTSTR lpOutputString // pointer to string to be displayed
);
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Ah, so easy...
Almost embarrassing I didn’t find it myself.
Unfortunately my project is compiled without language extensions (also developing on other targets) and without them I cannot include windows.h .
Do you know the correct signature for this function ?
I have tried with
extern "C" void OutputDebugString( char const * );
extern "C" void _cdecl OutputDebugString( char const * );
but the linker wouldn't have any of that.
Or is there a pragma to enable language extensions for a small part of a source file?
Thanks a lot // Peter
|
|
|
|
|
How about:
__declspec(dllimport) void __stdcall OutputDebugString(const char *);
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
In case anyone else was looking for this info here is what finally
worked ok.
extern "C" void __stdcall OutputDebugStringA(const char *);
|
|
|
|
|
|
Has anyone run into the problem of suddenly a CMapStringToOb member becomes invalid? Not a pointer either! After initialization it is valid but when I start to add an object I call assertvalid and it asserts!
ed
|
|
|
|
|
Sounds like someone is overwriting memory....
onwards and upwards...
|
|
|
|
|
I am working on a project where Im reading values from a machine every second, I then increment these values in a file, and then graph this file, every second I reset the plot and graph it again with the new values, when I reach the end of the upper bound of the x-axis, I want the lower and upper bounds to increment by 1 every second, Im working inside a forever loop and the code looks like so:
x=0; y=0;<br />
char* s;<br />
for( ;; )<br />
g1.plot_dataFile("data.dat", "test");<br />
Sleep(1000);<br />
g1.reset_plot();<br />
<br />
x++;<br />
if(x>20)
{<br />
y++;<br />
sprintf(s, "set xrange [%i:20+%i]", y, y);<br />
g1.cmd(s);<br />
}<br />
}
g1.cmd(string s) is a function to send commands to an external plotting application, and needs to take strings
While running, when x reaches 20, I get "Run-Time Check Failure #3 The variable 's' is being used without being defined."
Any help please!!!
We have a mathematician, a different kind of mathematician, and a statistician!
|
|
|
|
|
did you post all of your code? It looks like s never gets a value at all! You simply declare it:
char *s;
But never assign anything to it.
(p.s., at the very least, you should assign NULL to it when it is first created. Just good programming practice. )
Sometimes I feel like I'm a USB printer in a parallel universe.
|
|
|
|
|
Your right, I just set a large buffer for s and it worked
char s[1024] = {0};
Thanks v.m.
We have a mathematician, a different kind of mathematician, and a statistician!
|
|
|
|