|
Use F9 to set what's called a break point - you'll see a black dot appear by the line of code. Hit F5 to start debugging - the code will run to a breakpoint, and then stop. You can hit F10 to exectue a line of code at a time, and you also get a variable watch window, into which you can type variable names to see how their values change as each line is executed.
Make sure you're in debug mode You set that by clicking on Build | Set Active Configuration.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I would just like to add a little more detail to what Christian G (CG). said.
I assume that you are running your programs right now by clicking the icon with the !. This simply runs the app. like CG said, run your application by hitting the F5 key instead. You could also go to the Build menu, and select Start Debug. There are a lot of other useful commands on this menu.
When you know that you have a trouble area in your program, go to the line of code where you think that the problem is starting and hit the F9 key. Like CG said, this will set a breakpoint. A the program will halt its execution when it reaches this point.
At this point you can move your cursor over any variable to see what values they hold. There are a number of windows that you will want to open from the debug menu in order to get important information from the debugger.
The watch window will allow you to type in any of the variables that are in the current scope, or function, and you can see the values that they hold. If you have a class or a struct this is a really nice window because you can view all of the data member values of the object.
You can change the value of a variable in the right hand side of the watch window. This is very useful if you want to change the or set the value of a variable while debugging, with out writing code, or if you want to see how this new value will affect code execution.
The variables window will show all of the variables that are currently being used on the current line. Just like the watch window, you can change the value of the variables in the right hand side of the window.
You probably will not have to worry about the registers window for right now unless you learn more about x86 assembly. However the EAX register is the register where return values are always sent. So if you call an API function, but do not store the return value with a variable in your program, you can check this register.
The memory window is good for checking the memory at a particular address. So if you have a pointer and you want to see what memory it points to, type in the variable name in the address section, and dereference it ex. *lpString .
The call stack window is helpful to see what function calls have led upto the current function. You can also click on one of the previous lines in the call stack window to set the current debug context to one of those other functions. This will allow you to check variable values in a different function call that is on the stack. Some times you can uncover problems that happened in a previous function that caused problems later on.
Just like the registers window, you will not have to worry about the disassembly window until you learn more about x86 assembly.
A few more tips:
You can step to the next line of code with F10.
You can skip over a function call with F11.
If you want to stop execution of a program that is currently being debugged, hold Shift + F5.
You can set the current execution point by setting the caret to the line that you want to execute from and right click to get the context menu and select "Set Next Execution Point". This is very useful when you execute a statement with a wrong value and then you want to change the value in the watch window and re-execute a piece of code. Or if you want to skip over an entire section of code.
The most important thing of all, say you have a breakpoint set. The execution of your program has halted at that breakpoint, and you step through your program with F10. You finally find the problem, you can directly edit you code, make the one line fix or what ever the simple problem may be, hit F10, and Dev Studio will has if you want to edit and continue. If you choose yes, it will recompile your code, and you can continue executing the program from the same point without restarting the program. This works in most cases, but the compiler cannot recover after all of the changes that you make. SO you will want to limit this feature to small changes in your program.
I know there is alot of information here, and it may take you some time to get comfortable with all of the things that I have explained here, however these are the bare essentials to debugging in Dev Studio, and I stringly suggest you learn and use every one of these features. It will help you find problems quicker and you will learn your code faster as well.
I know there are a few other things that I left out so if anyone thinks that I left out anything important please add to this.
|
|
|
|
|
just wanted to say thank you before i go to sleep
|
|
|
|
|
I am new to template specialization and was trying to adapt the hash_map from Dinkumware to use keys of type string; by default, they accept only integer types.
This is the hash_compare class in header xhash
template<class _Kty,
class _Pr = less<_Kty> >
class hash_compare
{
public:
enum
{
bucket_size = 4,
min_buckets = 8};
hash_compare()
: comp()
{
}
hash_compare(_Pr _Pred)
: comp(_Pred)
{
}
size_t operator()(const _Kty& _Keyval) const
{
return (_Keyval);
}
bool operator()(const _Kty& _Keyval1, const _Kty& _Keyval2) const
{
return (comp(_Keyval1, _Keyval2));
}
private:
_Pr comp;
};
As far as I understood class template specialization, the following should work as a specialization for type string
#include <hash_map>
#include <string>
using namespace std;
namespace std
{
template<> class hash_compare <string, less<string> >
{
public:
enum
{
bucket_size = 4,
min_buckets = 8};
size_t operator()(const string& k)
{
long val = 0;
for (unsigned int i = 0; i < k.size(); ++i)
{
val += k.at(i);
}
return val;
}
bool operator()(const string& k1, const string& k2)
{
if (lstrcmp(k1.c_str(), k2.c_str()) <= 0) return false;
return true;
}
};
}
In the application, I test it with:
hash_map<string, string> maps;
maps["thomas"] = "george";
string val = maps["thomas"];
but the following compile errors occur
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
MainFrm.cpp
c:\sxl\include\xhash(475) : error C2663: '()' : 2 overloads have no legal conversion for 'this' pointer
c:\sxl\include\xhash(474) : while compiling class-template member function 'unsigned int __thiscall std::_Hash<class std::_Hmap_traits<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_s
tring<char,struct std::char_traits<char>,class std::allocator<char> >,class std::hash_compare<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_trai
ts<char>,class std::allocator<char> > > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allo
cator<char> > > >,0> >::_Hashval(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &) const'
c:\sxl\include\xhash(475) : error C2064: term does not evaluate to a function
c:\sxl\include\xhash(474) : while compiling class-template member function 'unsigned int __thiscall std::_Hash<class std::_Hmap_traits<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_s
tring<char,struct std::char_traits<char>,class std::allocator<char> >,class std::hash_compare<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_trai
ts<char>,class std::allocator<char> > > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allo
cator<char> > > >,0> >::_Hashval(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &) const'
Generating Code...
Skipping... (no relevant changes detected)
test.cpp
testDoc.cpp
testView.cpp
Error executing cl.exe.
test.exe - 2 error(s), 0 warning(s)
I appreciate any help on this
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
(A guess) Try making the two operator () methods const :
size_t operator()(const string& k) const
...
bool operator()(const string& k1, const string& k2) const
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, I just found that out ...
Also, is there any way to apply the concept of your block allocator to a vector? I am using the set_intersection algorithm to populate the vector.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Also, is there any way to apply the concept of your block allocator to a vector? I am using the set_intersection algorithm to populate the vector.
I've alredy answered that in my article's questions area (you might have not noticed, as email notifications to your address are being bounced back).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks
modified 29-Aug-18 21:01pm.
|
|
|
|
|
I found the problem. It was just a missing const keyword in the function declarations.
Don't bother about it...
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
everything is read but the third word???
aoltimewarnerinc AOL NASDAQ in 26 2674510
citigroupinc C NASDAQ ch 47 149881
cendantcorp CD DOW so 17 174795
ciscosystems CSCO NASDAQ ne 19 629955
generalelectric GE DOW te 37 31010800
intelcorp INTC NASDAQ ch 35 6303500
jdsuniphasecorp JDSU NASDAQ ne 7 281648
microsoftcorp MSFT DOW so 63 3478270
oraclecorp ORCL NASDAQ so 17 523466
qwestcommunicationsintlinc Q DOW te 10 170682
rationalsoftware RATL NASDAQ so 23 387952
sunmicrosystems SUNW NASDAQ so 10 399725
texasinstruments TXN NASDAQ ch 31 146157
tycointernational TYC DOW te 35 6496160
worldcominc-group WCOM NASDAQ ne 10 659215
Roger Daltry 000-00-0001 10000
Ron Howard 000-00-0002 12000
Pete Rozelle 000-00-0003 10500
Dr. Seuss 000-00-0004 10100
Mikhail Gorbachev 000-00-0005 15000
Jackie Joyner-Kersee 000-00-0006 17000
Paula Prentiss 000-00-0007 14000
Andy Gibbs 000-00-0008 18000
Shaquille O'Neal 000-00-0009 16000
Lynn Swann 000-00-0010 18500
S 000-00-0001 C 20
B 000-00-0001 C 20
B 000-00-0002 CD 10
B 000-00-0002 JDSU 50
S 000-00-0002 CD 5
B 000-00-0010 TXN 30
B 000-00-0010 TYC 20
B 000-00-0009 WCOM 20
S 000-00-0009 WCOM 10
|
|
|
|
|
char tempCN[30];
char tempST[30];
char tempMT[30];
char tempTM[2]; You're having a buffer overrun, because the type of manufacturer occupies two characters plus the terminating null character (which gets written on the next available position, namely tempMT[0] ). Reserve more space for tempTM (and as a general rule do not be so conservative when dimensioning things, or better yet, use std::string s).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I found the anwer like 2 minutes before reading your reply
i really appreciate your effort to solve my problem
THANK You so much
|
|
|
|
|
I had this code emailed to me last night and made several suggestions, std::string being one of them. I also pointed out that the NULL terminator takes a space in a char array.
I'm pleased he's changed his mind about posting his code, it will make it much easier to help him.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
i cannot use std::string
because my instructor told us not to.
but thanks though
|
|
|
|
|
It had just occured to me this would be the case. I'm at a loss why they make you learn to do things in a way you never will again, but I guess that just seems to be the way it is done. I learned from a book and learned the whole char* way, and I remember being amazed how much easier it was when I used the string class.
By the way, you need to tick 'display this message as is' when you post code, otherwise your #include statements don't get posted, because the < and > get interpreted as a HTML tag.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
probably making you understand that string is better than char*, obviously, when they discover that there is a string class and something called STL. There are many, many instructors who do not know a thing about STL.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Thomas George wrote:
There are many, many instructors who do not know a thing about STL.
I am not surprised to hear that. Pathetic, isn't it ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
well
i don't think he doesn't know about STL
but he just like to makes our life harder
he thinks that if you want to use libraries, then go program with JAVA
|
|
|
|
|
Marwan wrote:
he thinks that if you want to use libraries, then go program with JAVA
IMO he is a professional idiot if he means not to use libraries for production code. Where would any science be if we were not allowed to benefit from the work done before us ?
I COULD spend my life writing containers and algorithms, but why would I want to ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
As a software engineer, of course I agree with the whole code reuse thing. STL is a spectacular tool that I can't live without.
However, given the type of questions posted here by Marwan, it looks like he/she needs a good solid understanding of the basics of the language before introducing them to the relatively complex ideas of templates. Don't you think?
J
|
|
|
|
|
I understand that std::string is a typedef of a templated class, but would he need to know that ?
I dunno, I'm all for using char arrays early on, but at this point, he seems to have a lot of complexity introduced by virtue of not using a string class. I don't think 'ground up' is always the best way to learn, that's why I am against learning C before C++. You don't need to know about templates/namespaces/etc. to learn C++, you can just find out later that using namespace std; is bad code, and how templates work, etc. I believe C++ is an excellent learning language if you use the facilities it provides and then pull away the supports as you go on to learn the depth of what it can do.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I've just got a new computer, and I'm using my old version of vc 6 with service pack 5 on windows xp. The problem is that it often pops up messages of this sort...
http:\\joelholdsworth.members.beeb.net\strange.jpg
It seems to popup when I'm altering certain files, or looking at some of the mfc sources. The only way I can get rid of it is to press the cancel button repeatedly for around 30 seconds. This is intensly irritating! Does anyone know the cure? or what its caused by, or has anyone seen this problem, because its eminantly not caused by "\Device\Harddisk1\DR1" not having a disk in it!
With time we live, with money we spend!
Joel Holdsworth
|
|
|
|
|
Well, it's not msdev. We have three people with XP and VC6 with SP5 and everythings ok. I'd check XP out, this sounds rather serious.
Joel Lucsy (jjlucsy@ameritech.net)
|
|
|
|
|
Sounds more like a problem with XP or the hardware.
Do you get this error with any other software running on the PC ?
Whilst you say
Joel Holdsworth wrote:
because its eminantly not caused by "\Device\Harddisk1\DR1" not having a disk in it!
at that moment in time it maybe that the PC considers that it doesn't have a disk !!
We get a similar message on one of our servers which we believe is connected to the number of buffers allocated to passing data between the disks and the server, so your PC may be timing out in someway when writing to the disk. I would open it up and just check the cables as a starting point.
|
|
|
|
|
Is there a message or some sort of event that I could catch in my app if the machine is running low on virtual memory ?
Cheers
AndyC
|
|
|
|
|