166 Posted Topics
Re: Is the file in the same directory as the .h you are editing? | |
Re: You didn't post any code snippets, but it seems like you're reading or inputting uninitialized data. | |
Re: [CODE] switch( var ) { case 1: // ; break; default: std::cout << "Default." << std::endl; break; } [/CODE] Any case except the integer 1 will output "Default.", as it is the default statement. I cannot think of a different context for this question, if it's something else you'll need … | |
Re: It may be worthwhile to note that scanf ignores blank input, newline, and tab. (in the context you are using it) What I mean by this, is that blank input is still input, not EOF. | |
Re: [CODE] int gcd(int a, int b){ if (b==0) return a; #ifdef DEBUG printf("gcd(%d, %d)= ", b,a%b); #endif gcd(b, a%b); // where did you calculate which number was smaller? // is a%b really what you wanted here? } [/CODE] | |
| |
Re: [CODE] using namespace std; // It's better if you don't pollute your global namespace string str; // Why not declare this in main()? string stri; int inputString (int n); // Not sure I understand why you pass an int here bool palindromeTest (bool isPalindrome); // why do you pass this … | |
Re: To read from a file, you might try using std::ifstream If each item is on it's own line, one method you may try, would be storing each line as a std::string, and place them in an array of std::string. Then use your rand() variables to select an array offset (such … | |
Re: Might I inquire why this would be necessary, as your return type cannot change? Perhaps what you actually wanted was a template, I am not certain. [CODE] template <typename T> T* foo( T t ) {return &T;} [/CODE] In the code you have above, you may as well just use … | |
Re: You likely got the endianness wrong for reading data (as opposed to network endianness), but base 2 is how data is represented to a processor. | |
Re: Invisi, nArray is passed as a function parameter. What you are doing is making another array, using memcpy to move the contents of the old array to the new one, and then deleting the old one. You return a pointer (address of 0th element of array) to the new array … | |
Re: Do you know how much memory will be allocated during run time? For example, if you are resizing an array dynamically, based on packet input, the array could be a size much larger than it was at the time the program started. If you are not using any dynamic memory, … | |
Re: If you mean you want no intermediate data, you may want to sort during the merge. Before I continue I'd like to point out that you aren't actually merging your arrays, in the code you posted. You're overwriting one. You're also incrementing i twice. [B]Edit: I actually have no idea … | |
Re: [CODE] class Collection; // <-- pointers to Category class Category; // <-- pointers to array dvd[] and std::string description/name struct dvd_info { category* cat; std::string title; int year; double time, price; // <-- time in seconds, use a formatting function dvd_info() : cat(NULL), title("\0") { } dvd_info( cat *c, std::string … | |
Re: Please use code tags. This is your problem: [CODE] for (int i=0; i<5; i--) // you are decrementing i, it will become -1 { int times =5; // times will always be five [/CODE] Is this really what you want to do? [CODE] else if (guess > secret_number)&&(times == i--) … | |
Re: [CODE] std::stringstream ss; ss << "A line of text." std::ofstream file("lines.txt", std::ios::out | std::ios::app); if(file.is_open()) file << ss.str() << '\n'; file.close(); [/CODE] [B]Edit:[/B] Couple notes You may want to read about ofstream flags, they are non-trivial. Closing the file is important. You don't need to use a stringstream like I … |
The End.