Search Results

Showing results 1 to 40 of 266
Search took 0.02 seconds.
Search: Posts Made By: twomers ; Forum: C++ and child forums
Forum: C++ 16 Days Ago
Replies: 7
Views: 214
Posted By twomers
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
Posted By twomers
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
Posted By twomers
// 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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
Best worry about that 'useless junk' when you need to.
Forum: C++ 24 Days Ago
Replies: 9
Views: 382
Posted By twomers
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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
It might have something to do with while (nullexists = true). Do you mean ==?
Forum: C++ 27 Days Ago
Replies: 9
Views: 476
Posted By twomers
Uh.... what?
Forum: C++ 28 Days Ago
Replies: 6
Views: 341
Posted By twomers
cin.ignore() I think.
Forum: C++ 31 Days Ago
Replies: 11
Views: 527
Posted By twomers
>> 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
Posted By twomers
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
Posted By twomers
Looks good.
Have you considered negative bases, for fullness?
Forum: C++ Oct 29th, 2009
Replies: 3
Views: 303
Posted By twomers
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
Posted By twomers
And what errors are you getting?
Forum: C++ Oct 29th, 2009
Replies: 6
Views: 312
Posted By twomers
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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
Hmm. Can you show us your file?
Don't forget to delete []floatArray;
Forum: C++ Oct 29th, 2009
Replies: 10
Code Snippet: Text - Based RPG V2
Views: 899
Posted By twomers
Not exactly a snippet ;)
Forum: C++ Oct 16th, 2009
Replies: 3
Views: 510
Posted By twomers
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
Posted By twomers
As I said in post #4 :rolleyes:
Forum: C++ Oct 14th, 2009
Replies: 10
Views: 335
Posted By twomers
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
Posted By twomers
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
Posted By twomers
Code?
Forum: C++ Aug 13th, 2009
Replies: 2
Views: 218
Posted By twomers
>> 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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
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
Posted By twomers
Check your last thread!
http://www.daniweb.com/forums/post936815.html#post936815
Forum: C++ Aug 6th, 2009
Replies: 4
Views: 290
Posted By twomers
I go for a grazing cammel
double playerLifeForce;
Showing results 1 to 40 of 266

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC