C/C++ Program Performance: Validating Entries & Measuring Processing Power

AI Thread Summary
When validating user input in C/C++, using !cin.good() effectively checks if the input is numeric. To clear the input buffer after an invalid entry, cin.clear() resets the stream's state, while cin.seekg(0) is intended to reposition the input pointer, but may not be the best choice for clearing the buffer. A more effective method is to use cin.ignore() to discard invalid input until a newline is encountered. To monitor the processing power and memory usage of a program during execution, utilizing a memory profiler is recommended. Tools such as memprof for Linux and profiling tools available in Visual Studio can provide insights into resource consumption.
Hypercase
Messages
62
Reaction score
0
I,m writting code in C/C++ and when i validate my enteries(ensure they are numeric) i use !cin.good().

Also how do i clear the buffer after an invalid entry?
I usually use cin.seekg(0);cin.clear(); How do they work?
Is there a better way?

How do i find out how much processing power and memmory my prog uses as it runs?

-01000011 01101000 01100101 01100101 01110010 01110011.
 
Computer science news on Phys.org
You need what is called a memory profiler. I know under linux there is memprof and under visual studios 6 I think the program is called spy or something or other (Don't quote me on this).
 
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...

Similar threads

Replies
10
Views
2K
Replies
3
Views
1K
Replies
15
Views
4K
Replies
2
Views
10K
Replies
6
Views
3K
Back
Top