6,741 Posted Topics
Re: >but for simple cases (just like this one, where all it is doing is >storing a number), it's not bad practice to just make it public? It depends on whom you ask this question. Some people will tell you that public data is absolutely evil. Others will tell you that … | |
Re: >I don't recommend this method because it only works with summable values. Not to mention that you also risk integer overflow and undefined behavior. | |
Re: i r nt knowing wut t3h hell ur talkng abt lol rofl jejeje!!!!!111 So far you've committed every noob sin in the book. How about trying to ask an actual question, asking it in the form of a complete thought, and not using lame abbreviations and chat speak. This forum … | |
Re: You're going to have to ask a real question, and telling us how you've attempted to answer the question (before running to us) would help greatly. | |
Re: strcmp and friends already do a case sensitive comparison. It's easy to write a function that does a case insensitive comparison; it's just the same algorithm but with tolower or toupper matching the case: [code=c] int nocase_strcmp ( const char *a, const char *b ) { while ( tolower ( … | |
| |
Re: A stringstream is still a stream. When you read to end-of-file, you need to clear the state before you can do anything substantial with the stream again: [code=cplusplus] linestream.clear(); linestream << line; ... [/code] | |
Re: In general you need to write your own input mechanism that reads a character without echoing and prints a suitable mask character as a manual echo. C++ doesn't support raw input like that, so you'll have to drop to a non-portable solution such as getch: [code=cplusplus] #include <iostream> #include <string> … | |
Re: [code=c] #include <stdio.h> #include <stdlib.h> #include <time.h> int main ( void ) { int r; srand ( (unsigned)time ( NULL ) ); r = rand(); printf ( "random number = %d\n", r ); return 0; } [/code] | |
Re: You only need to explicitly free resources that you explicitly ask for. For example, a FILE* given to you by fopen needs to be closed, and a pointer given to you by malloc needs to be freed. | |
Re: I'd say append the delimiter onto cust if fscanf succeeds. You say this "didn't work", but that's a useless statement without a full description of what it does, what you expected it to do, and the actual code so we can verify that you did it correctly. | |
Re: There are two forms of getline that concern you in this case. The first is a member function of cin: [code=cplusplus] char buffer[BUFSIZE]; cin.getline ( buffer, sizeof buffer ); [/code] Note that the argument is an array of char, and the maximum number of characters you want to fill it … | |
Re: >Is there any options in control panel to delete a unwanted thread? No, can you imagine the havoc that would cause? If you want a thread deleted, contact a suitable moderator. We'll review your case and decide whether or not to honor the request. | |
Re: I assume you're using [ICODE]system ( "PAUSE" )[/ICODE]. My first inclination is to say that this solution is a bad idea anyway, and if it doesn't do exactly what you want, that's all the better for convincing you not to use it. :D The usual recommendation for pausing a program … | |
Re: >How can I exchange 2 variables values without using any 3rd temporary variable. Most likely your teacher is expecting this: [code=c] a ^= b; b ^= a; a ^= b; [/code] But I'd recommend you find a new teacher because your current one is likely too focused on archaic trivialities … | |
Re: When you find yourself using names like xxx0, xxx1, xxx0_1, xxx2_1, etc..., you should probably be using an array instead. | |
Re: Any decent compiler will allow you to define macros from the command line, so you can define your WINDOWS macro when compiling: [code] myawesomecompiler -DWINDOWS 1 mycode.cpp [/code] | |
Re: I'm curious why you expected a pointer to const char to be successfully converted to a pointer to std::string. The two are not compatible pointer types. The second example works because the string literal is used as a constructor argument in generating a temporary std::string object. | |
Re: >Cos' when I search on google and I when thought I had >found a great site, its actually for C programmers. The usage of the header is virtually identical between C and C++. The only difference is that if you use <ctime>, you need to remember that all of the … | |
Re: Somehow I get the impression that you want to run the timer in a separate thread. | |
Re: What you asked for, by my reading, is an array that grows automatically to fit whatever index you provide. So if you say int array[], then try to index array[100], the array will resize itself to have 101 elements. You [b]can[/b] do this with dynamic arrays and such things as … | |
Re: >for example what kind of function you recommend me to >use and what kind of loops you recommend me to use also Well, I'd recommend what the requirements say, since they're very specific about what functions and loops you should use. :icon_rolleyes: | |
Re: It's Friday, you have plenty of time to ask us a specific question and get a specific answer. | |
Re: >This is wrong, isn't it? If the value of argc really is changing (sometimes debuggers can be misleading) then looking for overflow would be my first task. It's entirely possible for memory overflow to spill into other variables and corrupt your data. | |
Re: Choose the one you like the most. :icon_rolleyes: By the way, if you want to learn a language "completely" you'll likely end up learning nothing else. For example, there's probably not a human on this planet who can claim complete knowledge of C++. | |
Re: Do a google search for linked data structures (ie. linked lists, binary trees) and you'll discover a good use for pointers. | |
Re: Most of the functions in the stdio library will take a pointer to FILE. scanf and printf assume stdin and stdout, respectively, so you might not have had cause to jump to something like fscanf and fprintf. The idea is to open the file and close the file, but in … | |
Re: >is it correct to say that to take advantage of polymorphism at >runtime, all of the base class functions that will be overriden must be virtual. Virtual member functions are how C++ supports run-time polymorphism, so it is correct to say that to take advantage of run-time polymorphism, you need … | |
Re: Don't repeat the static keyword in the definition of getWindowCount. | |
Re: >My answer which is the fastest way to achieve this on Linux compiled with gcc I'd say skip the standard stuff and drop down to the write function as a start. This removes a potential level of abstraction, but of course you should be profiling all of these options to … | |
Re: >But i have no idea on what kinda system to develop. I swear, I completely fail to understand how you can get passing grades through four years of classes and remain totally clueless. Are you seriously suggesting that you sat through lecture after lecture and [B][I][U]nothing[/U][/I][/B] peaked your interest? Or … | |
Re: It doesn't matter how the size is defined, you can't initialize an array member arbitrarily like you can with local arrays. You can default initialize it, but that's about as good as it gets, and with a const array, it's not terribly useful: [code=cplusplus] template<int s> class something { const … | |
Re: >Is the latest operating system critical for C++ developers in making a job change decision? The target system is a critical piece of information, if that's what you're asking. It doesn't have to be bleeding edge (C++ is older than any hardware and OS a game would reasonably target these … | |
Re: Clearly the same message is used for both good and bad rep, which means somebody didn't think very hard about the implications before trying to be all warm and fuzzy to users. ;) | |
Re: >Akikan [since I am a harem/romance lover at heart] It's hard to come up with a good harem series. I'll probably watch it anyway because Megumi Toyoguchi is one of the seiyuu. >Asu no Yoichi! Ugh. I've got horrible visions of yet another attempt a this cliché. I'll give it … | |
Re: >Both will fulfill your need. Though all things being equal, the first is arguably easier to prove correct without giving it much thought beyond knowing your "one past the end" value. | |
Re: >My theory is that if you program in a certain language it >affects the way that you are talking/writing/thinking. That's a good theory. I try to use the full breadth of my experience regardless of the language (ie. mixing useful concepts from different paradigms), but that's definitely a conscious thing. … | |
Re: >i want to program a videogame. I'd estimate that 99% of beginners start programming because they want to make games. >I bought c++ for dummies Hmm, I'm generally hostile toward "for Dummies" books because they're more often than not "by Dummies" as well. The quality of these books hasn't impressed … | |
Re: I can't decide if this is a joke or not. Anyway, the easiest way to look at the machine code (what people typically mean when they talk about "ones and zeros") is with a hex editor. Some hex editors even give you a binary view. | |
Re: Initialized the pointer to 0 if you aren't allocating memory. You can safely delete a null pointer and it will effectively be a no-op. | |
Re: I think you have your terminology mixed up. Can you give an example of one or two "exception handlers" that you're familiar with so we know what the hell you're talking about? | |
Re: >On the other hand a simple addition to tm_mday may produce >wrong dates and the real implementation (VC++ 2008) returns a >very strange results after mktime of that "new date". Granted I don't do a lot of date/time work, but I have yet to see what you've described as a … | |
Re: >I have specilized in Delphi [probably] since you were still wearing >short dresses; since Delphi was released by Borland in 1990. 1) How long you've been working with a language has no bearing on following Daniweb's rules. Since you're (so you claim) not a child, we expect you to be … | |
Re: Wow, grumpier. That was total BS. :icon_rolleyes: >The first line puts a space into the first char of a, and a zero into >the second char. All other elements of a are uninitialised. String literal initialization is equivalent to a brace enclosed initialization list. [ICODE]char a[LINE_SIZE + 1] = " … | |
Re: You probably forgot to terminate the last class defined in InputHandler.h with a semicolon. | |
Re: >Am I missing something. Yes. iDeveloper gave you the fix, but the reason for it is that you're initializing pointers to string literals. The problem isn't the pointers per se, it's the initialization of a pointer to a string literal. A string literal in C++ is defined as an array … | |
Re: Rather than bump your thread (which is exceptionally rude), why not show us what you've managed to find in the last [B]three months[/B] that helps solve your problem. If you've done nothing to help yourself aside from "gimme gimme gimme!" then I won't waste my time with a lost cause. | |
Re: It depends on which makes more sense at the application level. I tend to work front end to back end in my designs. Writing and using the interface first helps one to understand and better design the implementation. | |
Re: >Can anybody help me with an efficient C-Algorithm for this conversion? printf directly supports printing characters, decimal, and hexadecimal, so that's easy. Converting between ASCII and EBCDIC is also easy and highly efficient if you use two conversion tables: [code=c] unsigned char ascii[] = { /* All characters in ASCII … | |
Re: This sounds like homework, so until you show some effort, I'm going to give you the obligatory "Go do it yourself, slacker!" answer. |
The End.