How do you do it by hand? For math problems you should define the steps first instead of start writing code. Then you can put them in an algorithm.
Type: Posts; User: Hikaru
How do you do it by hand? For math problems you should define the steps first instead of start writing code. Then you can put them in an algorithm.
Maybe a vector of pointers into the other list?
#include <iostream>
#include <string>
#include <vector>
namespace Hikaru
{
using std::vector;
Ah, thank you. I wasn't sure if there was a problem I was missing or not. Thank you for the help. :)
I'm sorry, I don't understand. Are you trying to tell me that my strDup is wrong? strDup("") works as it should and strDup(NULL) is a problem with the call, not the function. I should have added an...
Ah, gomen. :o A better way would throw an exception.
#include <iostream>
#include <stdexcept>
#include <cmath>
using namespace std;
// the way you had it was okay, but this is probably...
Nice! I like this one the best, very clean! It uses the vector commands, which is cooooool :) Thanks for this![/QUOTE]
It might not work. C++ algorithms want a function object or function with C++...
You shouldn't print the result if there's an error. Maybe return a bool and only print if it's true?
#include <iostream>
#include <cmath>
using namespace std;
// the way you had it was...
foo doesn't look very useful. Maybe source should be where you get "random" and the function just returns the result of strdup?
#include <stdio.h>
#include <string.h>
char* modifiable(const...
Reading the file completely for every letter is really inefficient. You can use a map instead to store all of the letters and counts by reading the file just one time.
#include <cctype>...
Where in the world do washing machines require a passcode and go out of order if it's wrong?
You will need a loop. Only stop the loop when the passcode is right or when the number of errors...
With a vector. :)
std::vector<std::string> stringArray;
Always use them! :) C++ strings are a replacement for C strings. They're safer, easier, and can do more with less code. You can even get a C string from a C++ string with the c_str member function...
How do you know it'll be slower? I read a lot, and just about everyone says that people worry too much about speed when they shouldn't. You should write programs that are correct and easy to...
It's probably like the register keyword. It was a good idea at the time but someone realized that the compiler is better at the job than programmers. :)
Please excuse my rudeness, System_159. I'm going to point out some things I think could be improved in your program.
I'm told that macros are bad in C++. You should avoid them. Templates and...
That program should print the value of x, 0 to 99 without anything inbetween.
012345678910111213141511617181920...
Isn't that what you wanted to happen?
Thank you. :)
I think that if you do it right, there won't be many try/catch statements so checking return values is the one that clutters your code.
It looks like it.
I can only think of two ways. First, you can throw an exception. Or you can set a flag or something that code using the class can test for. fstreams use the flag, and I can't think of a C++ class...
I'm told that it specifically works on "files", for whatever definition of a file ANSI C uses. But you shouldn't listen to me. I don't know much about C yet. :)
Normally being the key word. :) What if you need more memory than the stack can hold? What if using static allocation would blow your executable way out of proportion? What if you don't know the size...
That's the problem, and I think it's because the left side of the || expression is saying "do this if the string isn't a null pointer". I'm sure that a quoted string will never be null, so the if...
Yeah, it is. :) It's also hard to use in C++ since it's a function designed for C. C++ has better stuff like strings and stringstreams that are really intuitive and easy to use, not to mention a lot...
It's easy if you want an exact match. Just compare the string variable with a quoted string.
#include <iostream>
#include <string>
using std::cout;
int main()
{
Have you tried setting the stream to print in fixed or scientific notation?
a_file << std::fixed <<"("<<P<<"*"<<L<<")"<<" ^ "<<T<<" /4= "<<A<<"\n";