Forum: C++ 16 Days Ago |
| Replies: 7 Views: 214 If you want an array you need knowledge of the number of lines in the file. The benefit of vectors is that you don't need knowledge, a priori (sp?), of the number of lines in the file. You can just... |
Forum: C++ 16 Days Ago |
| Replies: 7 Views: 214 I put the added lines in red.
edit: Whoops. Clearly I double posted. I meant to edit. but I hit reply. |
Forum: C++ 16 Days Ago |
| Replies: 7 Views: 214 // reading a text file
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main () {
string line;
vector<string> file; |
Forum: C++ 16 Days Ago |
| Replies: 7 Views: 214 Before the reading look do a std::vector<std::string> fileContents. Then when you do each line do a fileContents.push_back( line );
Also. You can just do a while( getline(fileStream,line) ) {... |
Forum: C++ 17 Days Ago |
| Replies: 11 Views: 283 It's probably an assignment, Dragon.
What problems are you seeing? It's hard for us to divine these answers without any real info. |
Forum: C++ 17 Days Ago |
| Replies: 11 Views: 283 Take a look at the code colouring in the above snippet. i.e. missing " in line 46. |
Forum: C++ 17 Days Ago |
| Replies: 3 Views: 224 Something like thisanimal *myAnimal;
myAnimal = new fish;
std::cout<< myAnimal->numLegs() << "\n";
delete myAnimal;
myAnimal = new cat;
std::cout<< myAnimal->numLegs() << "\n";
delete... |
Forum: C++ 18 Days Ago |
| Replies: 4 Views: 346 I'd guess that what's holding up the program is printing to the console output, which is a slow process. Try writing to a file instead and it'll probably help with speed. Then see if you need to... |
Forum: C++ 24 Days Ago |
| Replies: 9 Views: 382 It was sarcastic. There's no point in commenting every letter of code you write. It detracts from the readability, which is not the purpose of coding at all.
When only cining the cin.ignore();... |
Forum: C++ 24 Days Ago |
| Replies: 3 Views: 250 Best worry about that 'useless junk' when you need to. |
Forum: C++ 24 Days Ago |
| Replies: 9 Views: 382 You really should comment your code.
And on a side note check out cin.ignore(); after cin>>'ing. |
Forum: C++ 25 Days Ago |
| Replies: 6 Views: 321 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++ 25 Days Ago |
| Replies: 6 Views: 321 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++ 26 Days Ago |
| Replies: 12 Views: 298 It might have something to do with while (nullexists = true). Do you mean ==? |
Forum: C++ 27 Days Ago |
| Replies: 9 Views: 476 |
Forum: C++ 28 Days Ago |
| Replies: 6 Views: 341 |
Forum: C++ 31 Days Ago |
| Replies: 11 Views: 527 >> sizeof( any pointer ) is always the same
>> That happens to be true for the garden variety PC of today, but it is not true as a generic statement.
Also, on the same system fat pointers are... |
Forum: C++ 31 Days Ago |
| Replies: 6 Views: 275 You can only use that if you're assigning when defining, i.e.int thing[] = { 4, 8, 15, 16, 23, 42 };If you're not assigning you must use a constant size.
Alternatives.
Use pointers and... |
Forum: C++ Oct 31st, 2009 |
| Replies: 2 Views: 613 Looks good.
Have you considered negative bases, for fullness? |
Forum: C++ Oct 29th, 2009 |
| Replies: 3 Views: 303 You're passing in a const map, so you've gotta use a const_iterator:
map<string,unsigned>::const_iterator pos;
should work.
To explain. A const_iterator doesn't allow you modify anything in the... |
Forum: C++ Oct 29th, 2009 |
| Replies: 8 Views: 252 And what errors are you getting? |
Forum: C++ Oct 29th, 2009 |
| Replies: 6 Views: 312 Well... were you to decompile to hex and then recompile from modified hex you might be able to squander something... don't know if it'd work, though. Especially if the program depends on libraries... |
Forum: C++ Oct 29th, 2009 |
| Replies: 6 Views: 312 Well... were you to decompile to hex and then recompile from modified hex you might be able to squander something... don't know if it'd work, though. Especially if the program depends on libraries... |
Forum: C++ Oct 29th, 2009 |
| Replies: 3 Views: 303 I assume it's talking about the assignment of pos=wordlist.begin(). If so you'd imagine that wordlist isn't of type map<string,unsigned> from what the error says.
Can you post more code so we can... |
Forum: C++ Oct 29th, 2009 |
| Replies: 1 Views: 126 Hmm. Can you show us your file?
Don't forget to delete []floatArray; |
Forum: C++ Oct 29th, 2009 |
| Replies: 10 Views: 899 |
Forum: C++ Oct 16th, 2009 |
| Replies: 3 Views: 510 All that changes with iterators that aren't 'int's is the template argument. http://www.cplusplus.com/reference/stl/vector/erase/
std::vector<randomType> myVec;
// Fill the vector with something... |
Forum: C++ Oct 15th, 2009 |
| Replies: 10 Views: 335 As I said in post #4 :rolleyes: |
Forum: C++ Oct 14th, 2009 |
| Replies: 10 Views: 335 Try it with VS '08 so. Same code. Though get rid of the .h from the include files. |
Forum: C++ Oct 14th, 2009 |
| Replies: 10 Views: 335 You're probably using an old compiler. Might do good to update it.
Try putting a cin.get() and cin.ignore() before the return 0 in main(). Does the console window disappear, or does nothing turn up? |
Forum: C++ Oct 14th, 2009 |
| Replies: 10 Views: 335 |
Forum: C++ Aug 13th, 2009 |
| Replies: 2 Views: 218 >> My question is how can I use a member function of C at D and at D's child classes?
I don't understand that sentence. Can you elaborate or show what you mean with a simple example that shows what... |
Forum: C++ Aug 12th, 2009 |
| Replies: 3 Views: 356 Someone asked something similar before in another forum (http://cboard.cprogramming.com/cplusplus-programming/107469-custom-loose-coupling-string.html) and you could do something like this.class... |
Forum: C++ Aug 10th, 2009 |
| Replies: 2 Views: 479 You could have it so the constructor requires a flag to ID the allocated item... so something like...class base {
public:
enum derrivableIDs {
idBase,
idOne,
idTwo
};
... |
Forum: C++ Aug 9th, 2009 |
| Replies: 3 Views: 241 Hmm. Hard to say without seeing code, really. You could always using namespace namespaceOne::namespaceTwo; if you wanted to hide the thing. |
Forum: C++ Aug 8th, 2009 |
| Replies: 6 Views: 344 Curious. You should use std::strings really...std::string strItoA(int number) {
std::ostringstream sin;
sin << number;
return sin.str();
}Though Narue may tell you to generalise... |
Forum: C++ Aug 8th, 2009 |
| Replies: 3 Views: 182 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 8th, 2009 |
| Replies: 4 Views: 286 I said take it out of the loop. In your code it's in the loop in the function random and it's in the loop in main. It shouldn't be in either. Take it out from both of those and seed rand once in... |
Forum: C++ Aug 8th, 2009 |
| Replies: 4 Views: 286 Check your last thread!
http://www.daniweb.com/forums/post936815.html#post936815 |
Forum: C++ Aug 6th, 2009 |
| Replies: 4 Views: 290 I go for a grazing cammel
double playerLifeForce; |