|
|
hi...could anyone check the codings below? thanks.
#include <iostream>
#include <iomanip>
using namespace std;
class Bus
{
int number;
char startDepot[30];
char endDepot[30];
int departureTime;
public:
void update();
void display();
};
void Bus::update()
{
cout << "Enter the bus number (eg 83): ";
cin >> number;
cin.ignore(80, '\n');
cout << "Enter the start depot (eg Sengkang): ";
cin.getline(startDepot, 30, '\n');
cout << "Enter the end depot (eg Punggol): ";
cin.getline(endDepot, 30, '\n');
cout << "Enter the departure time (eg 1605): ";
cin >> departureTime;
cin.ignore(80, '\n');
}
void Bus::display()
{
cout << "Bus number : " << setw(3) << setfill('0') << number << endl;
cout << "Start depot : " << startDepot << endl;
cout << "End depot : " << endDepot << endl;
cout << "Departure time : " << setw(4) << setfill('0') << departureTime << endl;;
}
int main()
{
int count;
Bus *b;
cout << "How many buses are there: ";
cin >> count;
b = new Bus[count];
char choice;
int num;
do
{
cout << "u. Update\n";
cout << "d. Display\n";
cout << "e. Exit\n";
cout << "enter selection: ";
cin >> choice;
switch(choice)
{
case 'u' :
cout << "enter bus number (1-" << count << "): ";
cin >> num;
b[num-1].update();
break;
case 'd' :
cout << "enter bus number (1-" << count << "): ";
cin >> num;
b[num-1].display();
break;
}
} while (choice != 'e');
delete [] b;
return 0;
|
|
|
|
|
so...?????
what is your question ?
TOXCCT >>> GEII power
|
|
|
|
|
does the coding looks logical?
|
|
|
|
|
|
It has very severe error that it is without comments. And believe me my friend a code without comments is just a deadbody.
cheers
|
|
|
|
|
How to delete a file which name is contained in the CString variable "m_csPCFileName" ?
I tried this but it doesn't seem to work:
char* pTempFileName = "";
strcp(pTempFileName,m_csPCFileName); //Conversion CString to CHAR*
CFile::Remove(pTempFileName);
I have an handled exception error message...
Thank's for advance
|
|
|
|
|
Anonymous wrote:
strcp(pTempFileName,m_csPCFileName); //Conversion CString to CHAR*
false strcpy() is not designed() to work with CString s.
use the CString::operator (LPCSTR) () instead.
TOXCCT >>> GEII power
|
|
|
|
|
strcpy works just fine with CString. However, the code in the first message is badly broken.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|
How about a simpler function, DeleteFile( lpszFileName );
It's a standard Win32 api.
--
Joel Lucsy
|
|
|
|
|
Hi,
I have a batch file that is used for daily build and has large number of projects build from the command line using this file.
The Command Line command that does the build using the batch file is
msdev xmlTest.dsw /MAKE "BuildAll - Win32 Debug" /OUT ..\..\xmlTest.log
This build is based on the settings made to the .dsp files present in the Workspace and works fine for existing settings.
Now i want to modify the batch file to build with the option /ZI or /Zi turned on in order to generate the .PDB files.
So the thing is that i have to build first without /Zi or /ZI option and next set this option and run the second time to get the .pdb files generated.
What is that i need to modify in the batch file to make both the options working from the command line..
I think it has something do to with the environment variable setings....but have no idea how to do it...
Thanks
AR
|
|
|
|
|
You could try using SET CL=/Zi . I'm not sure if this environment setting propogates to cl.exe via msdev, though. You'll also need SET LINK=/DEBUG to get the linker to generate the final pdb file.
I follow John Robbins'[^] prescription - I always generate PDB files, for both Debug and Release builds. The overhead of generating a PDB on the final code is minor: the executable's .debug section contains the path to the generated PDB file. One small caveat is that specifying /DEBUG to the linker changes the default /OPT setting; to discard unreferenced code and data (the default in Release mode), you should also specify /OPT:REF .
Having the PDB file allows you to at least be able to see source and get a call stack when trying to debug a Release build. Robbins has produced a number of useful tools such as CrashFinder (http://www.wintellect.com/about/instructors/robbins/code.aspx[^]) which allows you to map a crash address to a source line, and PrivateStrip (http://www.wintellect.com/resources/newsletters/2000/dec2000.aspx[^]) for removing private symbols from a PDB suitable for giving to a customer to get better crash information.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Iam not sure if we can use SET CL = /Zi with the MSDEV command. well i get what exaclty you are trying to tell but i didn't get exactly what iam looking for.
MY first priority of looking at it is to have a sinle batch file that could do both the release builds with and without .pdb so essentially i need to do something in order to set the option after the first build.
If i can make use of the SET CL = /Zi ...with msdev. can you let me know how to use in the order..
|
|
|
|
|
can a application restart by itself, any way to do that.
or can a NT service restart by itself.
|
|
|
|
|
You can certainly use CreateProcess to create a new instance of your application, then quit your current process (the way you do this will depend on your application, for example, you might need to close your main window).
Service processes can be configured in the Services snap-in to automatically restart if the process crashes. See the ChangeServiceConfig2 API.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
i have a 24*7 highly database intensive mfc application. using cdatabase and crecordset objects.
it starts with 8mb and gradually increases to 34 mb (peak is shown as 60 mb)by task mgr, withing one day. Im sure of no memory leak. But sure windows is reserving (may be caching) the memory for my application, which is shown accross my application by task mgr.
is there any way to avoid this behaviour and make the application to take only that memory taken in the first couple of hours and not more.
So my question without any memory leak is this behaviour possible. any remedy to avoid this behaviour. like registery settings to avoid caching or something else...
|
|
|
|
|
The MFC database stuff will tend to cache rows if you don't use the right cursors.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
plz can any one guide me how to dump(apppend) the record(data) into excel sheet using Vc++(MFC wizard) and also to write program which controls data(i,e to delete data using a program ).
|
|
|
|
|
HI all,
supposed that my multithreaded program protects data with MFC CCriticalSection and it works fine on machine have one CPU. Is there any steps must I take to have the program worked on same platform with multi CPUs. Is this safe with CCriticalSection synchronization?
Many thanks,
Do Manh Hung
|
|
|
|
|
On a multi-CPU platform, the CPUs are given threads as required, and the second processor will take responsibility of the threads after a certain amount of load is placed on the first.
I believe that the threads given to one CPU are always handled by it. This means that the CPUs don't work together on a single thread, instead, both CPUs handle their own threads, and this thread-sharing is done by the OS.
Not sure, though.. However, the CCriticalSection object protects a resource or a piece of code for exclusive access for a single thread. As such, it shouldn't make a difference on what CPU is handling the thread at the given time: the thread from which the locking method is called is given an exclusive access to the forementioned resource, and the CPU just processes the thread. If another thread tries to access the resource, a violation is generated.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thank Keskinen,
As you pointed out, one CPU will handle given threads and "If another thread tries to access the resource, a violation is generated". Did you mean that when one CPU try to access another resource handled by other CPU, error will occur or it is not safe, for short?
Do Manh Hung
|
|
|
|
|
Unless the threads are affinitized using the SetThreadAffinityMask API, any thread can be scheduled to run on any CPU (if a mask is set, the thread can be scheduled on any CPU in its mask) at any point that it is ready to run. Windows tries to run threads on the same CPU they last ran on if possible, to exploit caching, but you can't rely on this - it won't hold up a thread that could run because its preferred CPU is not available.
Only one CPU can run a given thread at a time. A particular thread of instructions will never run in parallel with itself.
Also, Windows uses a pre-emptive scheduler - it can switch between threads in between any two CPU instructions, which means that some operations (for example, incrementing a variable's value) which require copying from memory into a register, modifying the value and writing back to memory can get interrupted before completing. If two threads try to increment a variable simultaneously, even on a single CPU system, you can get a situation where only one increment ends up being written back.
To prevent this, Windows provides synchronization objects and interlocked functions. The interlocked functions allow primitive values (usually a long ) to be modified in a way that cannot be interrupted and forces any other CPU to wait before accessing that memory location - an atomic operation.
For more complex data structures, you need to use a synchronization object such as a critical section. For critical sections, only one thread can enter at a time. If the critical section is already taken by a thread, any other thread will block (cease executing and wait - the OS scheduler will not assign it to a CPU) until the owning thread releases the critical section. Some synchronization objects guarantee a particular order in which threads will be released, but the critical section is not one of them.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Yes, a critical section will work fine no matter how many CPUs you have.
However, be aware that if you do have any bugs where data isn't protected from simultaneous access, they will likely be hidden on a single-CPU machine. So it's always a good idea to test on a dual CPU machine to look for those kinds of bugs.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
I even hear the Windows "OMG I booted up fine" sound.
-- Paul Watson diagnosing hardware problems.
|
|
|
|
|
So it's always a good idea to test on a dual CPU machine to look for those kinds of bugs.
This can not be stressed enough. If someone writes a multithreaded application, they MUST have a dual CPU system to test it on.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|