Forum: C++ 29 Days Ago |
| Replies: 9 Views: 405 You really should comment your code.
And on a side note check out cin.ignore(); after cin>>'ing. |
Forum: C++ 29 Days Ago |
| Replies: 6 Views: 331 Hmm. I dunno.
I was demonstrating how to loop around safe bounds, not how to handle exceptions.
What's the point in throwing a throw if you're not gonna catch just for the throw when I know it's... |
Forum: C++ 30 Days Ago |
| Replies: 6 Views: 331 If you want a 2d vector you can do something like:
#include <iostream>
#include <vector>
// These just make the notation used in the program easier
typedef std::vector<float> xVec;
typedef... |
Forum: C++ Aug 8th, 2009 |
| Replies: 3 Views: 185 Consider what happens if all the numbers in the array are negative. Then the if(a[i]>max) will never return true. There are two ways you can do this. Either set max to INT_MIN or set max to a[0] and... |
Forum: C++ Aug 6th, 2009 |
| Replies: 4 Views: 312 No.
Everyone thinks the one they use is the best. Do something that makes sense. Nobody will complain too much so long as it's sensible. |
Forum: C++ Aug 2nd, 2009 |
| Replies: 1 Views: 280 I'd imagine if you were to wait in the for loop for about a second per iteration it'd be different.
The problem is that you're reseeding the rand function so quickly it's being reseeded off the... |
Forum: C++ Jul 19th, 2009 |
| Replies: 14 Views: 616 You should read about getline here, http://www.cplusplus.com/reference/iostream/istream/getline/
Personally, I'd use std::string-s and getline... #include <string>
#include <fstream>
#include... |
Forum: C++ Nov 22nd, 2008 |
| Replies: 12 Views: 1,373 Well, there are two common ways you can represent complex numbers. One is a+ib where i is the root of -1, which is NOT -1. This is called the Cartesian (or rectangular) coordinate system. The second... |
Forum: C++ Oct 4th, 2008 |
| Replies: 2 Views: 417 Why don't you just do myArray[counterArray] = new unsigned long; in the allocation loop? And don't forget to delete everything too! Considering what you basically want is a 50-element array why don't... |
Forum: C++ Jan 20th, 2008 |
| Replies: 10 Views: 3,875 The simplest thing I can think of is to use some kind of pop3 library... I'm sure there are probably some available. ( first hit -- http://www.marshallsoft.com/see_4c.htm No idea on how good it is )... |
Forum: C++ Nov 19th, 2007 |
| Replies: 12 Views: 3,914 So it's better to have base-protected-getters than protected variables? |
Forum: C++ Nov 16th, 2007 |
| Replies: 5 Views: 3,349 If all you want to do is wait for a while you can use sleep...:
#include <windows.h>
int main() {
// Do something
Sleep( 1000 ); // Sleep( miliseconds );
// Do more somethings
return 0;... |
Forum: C++ Nov 6th, 2007 |
| Replies: 5 Views: 595 Don't forget that you need a ; at the end of your class defn -
class class_name {
// ...
};
In C when you created a struct and didn't define it with a typedef you'd have to say:
struct... |
Forum: C++ Nov 3rd, 2007 |
| Replies: 4 Views: 759 Wow. We give out about people not giving us enough code all the time ... but all the code... one would think it's a good thing...
However, I, for one, am not going to look at any of them. I think... |
Forum: C++ Oct 29th, 2007 |
| Replies: 18 Views: 12,354 >> I didn't compile or test this so it might contain errors
Neither using namespace std nor std::s are there! Neither is iostream. Tut tut tut. |
Forum: C++ Oct 14th, 2007 |
| Replies: 12 Views: 2,139 void Student::input ( )
{
cout << "This program reads a student name and the number and name of the classes.\n" ;
cout << "Enter the student name: " << flush ;
getline ( cin , name... |
Forum: C++ Oct 9th, 2007 |
| Replies: 16 Views: 1,635 >> That's all?
Is that a question or a statement?
>> I just don't get why to got rid of all their code which just needed an extra line to make it valid.
I don't get why you keep on... |
Forum: C++ Oct 9th, 2007 |
| Replies: 16 Views: 1,635 >> feel yourself unequipped to defend it
I did defend it:
Gah!
>> OP needed was another line of code to make their original statement valid.
Function.
Yes. But the OP's underlying... |
Forum: C++ Oct 9th, 2007 |
| Replies: 16 Views: 1,635 >> Is it.
I believe so anyway.
>> Clarity is paramount over everything else.
I agree, but I don't find the code I presented to be particularily (or in earnest any way), confusing. Do you? If... |
Forum: C++ Oct 9th, 2007 |
| Replies: 16 Views: 1,635 Just cause it's easier:
bool eq1( int &v1, int &v2 ) {
if ( v1 == v2 )
return true;
else
return false;
}
bool eq2( int &v1, int &v2 ) {
return (v1==v2 ? true : false); |
Forum: C++ Oct 9th, 2007 |
| Replies: 16 Views: 1,635 OK.
You know you can do:
if ( something == something_else ) { ... }
If something does indeed equal something_else then the parameters return true through the == operator, right (and if it... |
Forum: C++ Sep 30th, 2007 |
| Replies: 19 Views: 9,754 About the spaces it might be worth making a string to do them rather than looping:
#include <iostream>
#include <string>
int main( void ) {
std::string spaces( 10, ' ' );
std::cout<< '#'... |
Forum: C++ Sep 29th, 2007 |
| Replies: 3 Views: 1,099 What you've gotta remember is that there you're going to have to delete the pointer to second in first's member destructer - unless I've misunderstood whenever you use new you must use delete. So... |