|
A declaration looks like this: return type name(arg list);. It's predefined, that means that you only have to use it! Therefore it should only appear in a source file!
You should seperate 3 things:
1) declaration => Header File
2) Implementation => Source File
3) Call to a function => Source File (within other functions)
A Implementation looks like this:
return type name(arg list)
{
// source code
}
I assume you know how to call a function...
hope this helps
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
srand() seeds the pseudo random number generator. Many, if not most, developers just use the time function for this.
rand() returns a pseudo random number from 0 to RAND_MAX. To get a random number in an range, use the modulo operator with the max value plus one. In other words to obtain a random number from 0 through 5 do the following:
int x = rand() % 6;
Never heard of nrand().
|
|
|
|
|
Thanks, I'll try those out.
Dave
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|
|
|
|
|
The following two code examples do compile, but only yield a message that says to press a key to continue. Shouldn't I see a random number "x" cout to the screen from rand ( ). What am I doing wrong here?
<br />
#include <cstdlib<br />
#include <iostream><br />
<br />
using namespace std;<br />
<br />
void main()<br />
{<br />
int x = (rand() % 150) + 1;<br />
cout<<x<<endl;<br />
} <br />
Here's the other example...
<br />
#include <cstdlib><br />
#include <iostream><br />
<br />
using namespace std;<br />
<br />
void main()<br />
{<br />
int x = rand() % 151;<br />
cout<<x<<endl;<br />
}<br />
Thanks, Dave
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|
|
|
|
|
They both work fine for me (Win/XP, Vstudio v6).
What compiler/system are you using?
|
|
|
|
|
I can't believe what my problem was. I'm still learning VC++ 6.0. I wanted to try some new code so I just replaced the code on my screen with the new code. I went to compile and evertyhing looked ok, it wasn't. I found something weird (at least I think it is weird) about VC++ 6.0, it doesn't compile what's on your screen unless you save it first. The source cpp file listed in my view folder did NOT change with the new code I typed in. VC++ compiled the cpp file listed in the view folder, not the cpp file I had open in front of me. So the code in front of me (that was all messed up) was seemingly compiling ok, in reality it was the cpp file in my folder that was compiling ok instead.
I did get rand( ) to work finally. I used time(0) as the argument and it works great. Thanks much, Dave
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|
|
|
|
|
Ok, I'm completely baffled. I am using a CFile to store information for my CDocument class in an SDI application and passing the CArchive to the serialize function. (We'll call the filename "datafile.dat") I have had absolutely no problems with my code up until this point. I am simply storing 4 CStrings in the file ("datafile.dat"). These 4 CStrings just hold locations of further files which the application will access. I am running into a problem when I try to open "datafile.dat" for storing...if any of the 4 CStrings is holding the address of a network file (a file on another computer) then "datafile.dat" will not open for storing. If the 4 CStrings hold the paths of local files or pretty much anything else, then "datafile.dat" has no problem and stores the information. Keep in mind, the location of "datafile.dat" is local and application specific...this file is not shared between multiple instances of my application.
I'm including my code snippet where I try to open the CFile for storing. This code works fine for all cases EXCEPT when one of the 4 CString variables (which is all that gets stored) contains the path of a network file instead of a local file. In the case of the network file path, the code gets stuck in the while loop. Oh, one other thing...the file DOES exist, it is created in the constructor if it doesn't currently exist, which by the time this code is reached, the file exists.
/* My Code for opening the file for storing. The FileName variable never changes after being initialized (I've message boxed it, the FileName variable isn't causing the InitFile to not open, it is the correct file at all times). */
CFile InitFile;
while ( !InitFile.Open(FileName, CFile::modeWrite | CFile::shareExclusive) );
CArchive archive(&InitFile, CArchive::store);
Serialize(archive);
archive.Flush( );
archive.Close( );
InitFile.Close( );
Thanks for taking to time to read such a long post, and I hope I was clear in my explanation, and that somebody understands why this file isn't opening!
Douglas A. Wright
dawrigh3@kent.edu
|
|
|
|
|
I don't know the source of your problem, but maybe you can try to use a CStdioFile for it and open int in CFile::typeBinairy mode. Maybe this will work.
Hope this helps...
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
I found the answer to my own question, but thought I should post the solution in case somebody comes across the same problem. It turns out, that the code is fine...the problem came that my FileName variable only held the local filename, not the entire path of the file. I used SelectFile controls to choose the paths of the 4 files I referred to as my 4 CStrings. When I chose a network file, I was also changing the current directory, which is where my problem occurred. I created the file that my InitFile was trying to open in my constructor (if it didn't already exist) but now that I changed my directory, this file cannot be found. The solution was simple, in my constructor when I created/read the "Datafile.dat", I called the GetFilePath( ) function and set this string in FileName. Everything is happy now!
Thanks for those who replied, or was in the process of trying to figure out what to reply!!! ;)
Douglas A. Wright
dawrigh3@kent.edu
|
|
|
|
|
The contents of a file will never cause it to fail to open. The correlation between failing to open and containing network paths is purely coincidental.
The third parameter to CFile::Open() is a pointer to a CFileException object which is filled with error information if the file can not be opened.
Inside your while loop, check the results of this exception object (use CException::GetErrorMessage() and display it with a message box) to see exactly why it's failing.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
Can I reset a Timer without doing a KillTimer?
For example if I created a Timer as
oldTimer = SetTimer(0, 2000, NULL);
later
SetTimer(oldTimer, 5000, NULL);
Is this going to reset the Timer to the new time.
Thanks,
gc
|
|
|
|
|
I don't know, try it and find out and let us all know.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
It has been a while since I played around with them but I'm pretty sure that if you try SetTimer as you suggested, the second one will fail since the timer with the given id has already been allocated. You can check the return value for yourself to be sure though.
|
|
|
|
|
From MSDN:If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored. So there's no need to "reset" a timer (which you can't actually do anyway, you can only create it or kill it).
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Michael, thanks for your response.
I tested with the example program and WM_TIMER message is sent after the current time-out value elapsed.
|
|
|
|
|
Hi, I'm looking to access the Boot Sector (Absolute 0) and posibly edit the contents there (or slightly beyond there, so as not to adversly effect the OS).
I know that quicken tried this and ticked off their customer-base - me included. However, the powers that be in my life deem that I must do this also.
So, the question is: How can I access the Boot Sector on a FAT32 system using VC++ 6.0? Or do I have to use Assembly (Which I don't know - at all )?
Anyone?
|
|
|
|
|
|
While I've got your attention, I wanted to say thank you for some of your articles on The Code Project! They were extremely helpful.
Oh, and thanks!
|
|
|
|
|
|
Be aware that on NT, if you modify the MBR or any boot sector, the OS will come along a few seconds later and restore the sector from a backup copy that it keeps. You have to lock the volume before writing to the sector (however I don't know off-hand how to do this).
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Hi (for the second time today),
I'm getting the following error and im not sure why -
d:\projects\common\winctrls.cpp(145) : fatal error C1010: unexpected end of file while looking for precompiled header directive
When you double click the error (in VC6) it takes me to the end of "WinCtrls.cpp", which is the implementations of all of the class functions defined in "WinCtrls.h". Now I dont know much about the compilation process, but the only "non code" bits I have are a #IFNDEF, a #DEFINE, and a #ENDIF. Does anyone know what may be wrong. I'll try and explain further if needed.
Many thanks again
Zak
|
|
|
|
|
did you forget to add #include <stdafx.h> as the FIRST include statement in your .cpp file ?
have you forgotten something in a .h file somewhere ?
maybe an #endif or a closing brace } or a ;
Maximilien Lincourt
"Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
|
|
|
|
|
In addition to the other reply you got you should also check to ensure that any third-party installed headers in 'some' directory are listed in your include paths in the Project Settings tool.
In the C++ tab under 'include directories' Add the *.h/hpp file to your 'include directories' settings:
ie: C:\thirdpartysdk\inc
In the Link tab under the 'Input' category, add the name that contains the library (*.lib file) to the class you're implementing.
As above, enter the path to the directory containing the lib file in the 'Additional Library Path.'
I know this is more than you need at this moment but I think it will help out in the future.
|
|
|
|
|
|
speaking of which, didn't the faq appeared on the top of the window ? I had to search for it yesterday
Maximilien Lincourt
"Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
|
|
|
|