It's unnecessary. Simply be looking at the control statement you should be able to understand what variables control the loop, and what conditions the loop continues/stop execution.
There are...
Type: Posts; User: AH_Tze
It's unnecessary. Simply be looking at the control statement you should be able to understand what variables control the loop, and what conditions the loop continues/stop execution.
There are...
A string and an array of chars have similiar functionality. Strings are preferred unless it's part of the program specification (some teachers have a fetish for char arrays (c-strings))
Could you...
I'm not quite following the program logic, but it looks like you need a sub loop.
For a given string, you could have something like:
// I think key is the right string
for(int current = 0;...
Now I'm curious. I ran this, and checked strlen() immediately after input, which gave lengths greater than the size of the array. Is the program writing past it's bounds?
If so, you might want to...
I just ran it (sans missing end bracket on name), and it worked. It read in first 20 characters and ignored the rest when assigning name. Seemed to have the same behavior as when I used a name that...
well if it's time for that conversation...
Accelerated C++ by Koenig and Moo is a great book, especially if you have past programming experience and want to start using the powerful tools C++...
You could make a class which knows it's name is a user-entered string. ie it could output, change, and compare it's "name."
I'm going to have to join the people who are very confused about why...
You're asking for a bool but getting string::size_type.
It will always evaluate to true except for when the target string is the first character of someString.
The -1 is an implementation detail. If you used it, you'd be obfuscating what you're doing and assuming the compiler will give it the correct type.
If you're looking for an explanation, many (most/all?) implementations define npos as such (in logic if not in syntax):
size_type npos = -1;
size_type is going to be some type of unsigned...
Not sure I understand. Are you trying to derive a vector sub-class that provides bounds checking?
If so, vector::at() already does bounds checking. It throws a std::out_of_range exception if the...
what happens if you have a const Array_class?
Much cleaner. String has been implemented so you can use the stream insertions with it (cout << and cin>>). You can also directly compare them, no messing around with strcmp.
#include...
You can't use cout on a c-string.
I'm not sure what the best way to output a c-string is (you could write the function to loop through and print each char, but it may have been done better/before...
Could he mean if there is a new[] inside a conditional? At which point this might happen:
int* ptr_var = 0;
//... possibility of ptr_var = new int[SIZE]
delete [] ptr_var;
okay, a function uses pass by reference can handle a literal, but only if the parameter is constant .
I'm guessing that this shouldn't be a problem for an Add() function. The only time you'd need a...
As you discovered, C++ views literals differently as they don't have addresses.
EDIT: Damn, that was stupid.
/me goes off to play with this, ignore the following as it doesn't work.
There must...
Wouldn't using the std namespace in a class pollute the namespace of any code the uses the class?
marginally related question, but would there be a real value in using a global variable for E instead of a macro? I remember hearing something to that effect, but I couldn't follow the justification...
What is the point of this "house house" thing?
Within a class' method, such as menu(), you have access to all of the class member data and methods, so why would you need to make a new object of...
Not seeing it immediately. The alive() and neighbor() functions look error-prone.
If you want to find the error, I'd probably write a seperate driver program so you can test those two individually....
i'm piecing through this. One random style suggestion, is that you should really use 0-indexed lists. If you don't stick with the idiom, it gets confusing, as you always have to keep track of if code...
Interesting. What does the input file look like?
This sounds a lot like either an assignment, or something you should be doing yourself.
I like being helpful, but not doing your work for you. If you have a conceptual, syntactic, or just really...
The logic is not too hard.
The general concept is to start by assuming the first element is the largest.
Then compare the current maximum value the next element. If the next element is larger,...