6,741 Posted Topics
Re: [QUOTE]I am trying to figure out the advantages of C++ STL containers over C.[/QUOTE] C++ has STL containers and C doesn't. Case closed, Sherlock. I get the impression that you're building a fallacious argument about C++'s superiority over C, which is a complete waste of time because it lacks objectivity … | |
Re: [QUOTE]I don't believe there are any times when using this-> is harmful, but there are certainly times where NOT using it can produce an ambiguous case that will cause you headaches.[/QUOTE] Of course, that's assuming you don't use any kind of naming convention. Prefixing/suffixing data members with an underscore or … | |
![]() | Re: [B]>square root of N... N loglogN... N log^2 N... N^2 log N... >and many more. How do I know how those look like?[/B] They're generally not as clear cut as N and N^2 because you typically don't see this kind of loop directly: [code] for (int i = 0; i … |
Re: >Any ideas why I can't include it? Yes, fstream.h is not a standard C++ header. Nor is iomanip.h. Come to think of it, void main isn't standard either (regardless of what your compiler's documentation says). If you want to go fully standard, use C headers with the .h dropped and … | |
Re: You should really reconsider relying on non-portable behavior (eg. fflush(stdin)) and non-portable functions (eg. gets_s) if you can avoid it. I'd also recommend merging your months into an array. Even if you waste a few elements of an array, it's still a win in complexity if you consider nothing more … | |
Re: I'll take a look at it for you. You can find my email on my homepage, and my homepage on my Daniweb profile (giving spammers a harder time than simply posting it here). | |
Re: [QUOTE]It is posible in a linked list implementation,the nod to hold more then one information ?[/QUOTE] It can hold whatever you want. You're the programmer after all. :icon_rolleyes: However, since most linked list libraries are fairly generic, they'll hold only one item of either template or void* type and that … | |
Re: [QUOTE]stringstreams are a much cleaner solution than dirty C sprintf functions[/QUOTE] Really? The only "dirty" thing I can think of (tedious would be my choice of words) is no std::string support in sprintf. So you need to figure out the maximum size of the file name buffer beforehand. Aside from … | |
Re: strlen is declared in <string.h>, or <cstring> if you want your stuff in the std namespace. | |
Re: [QUOTE]Prime_Finder findprimes();[/QUOTE] You've independently discovered a rather subtle problem with C++'s grammar. This line is actually interpreted as a function declaration. The function is called findprimes, has no parameters, and returns and object of type Prime_Finder. To define an object with the default constructor, omit the empty parens: [code] Prime_Finder … | |
Re: [QUOTE]Is using other then int types is part of the ANSI C?[/QUOTE] The behavior is implementation-defined if you use anything other than _Bool, signed int, or unsigned int. | |
Re: It's an order of operations problem. Inside the loop, you're always testing the next pointer in temp, which is always uninitialized. Take some time to test out how for loops manage the counter variable, because a lot of code relies on that behavior and it's easy to write code that … | |
Re: [QUOTE]im tryin to generate random strings and store them in an array. can anyone please show me? [/QUOTE] It's easy if you really want random (pseudorandom) strings from a source: [code] #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> void random_fill(char s[], size_t n, const char *src) { size_t src_len … | |
Re: Just post your code, already. Ideally write up a bare bones program that exhibits your problem without being excessively long. Playing twenty questions is unproductive, especially when the problem sounds like something most of us can solve at a glance. | |
Re: Arrays don't grow or shrink. If you need dynamic sizing, use an std::vector instead. In fact, you should prefer std::vector in favor of arrays anyway, because they're easier to work with. [edit: Bah! This is the C forum. Ignore this post] | |
Re: It looks like you really want a set, not a vector. | |
Re: [QUOTE]but then it dont work anymore[/QUOTE] WTF do you mean by "it don't work anymore". Are we to read your mind for sufficient details? I suspect you're encountering a very simple and common problem with scanf not playing nice, but I can't say for sure because in that relatively large … | |
Re: Clearly Visual C++ 2010 is smarter in terms of implicit standard headers. You failed to include <string>, and the compiler rightly complains. The others don't complain because <string> is probably included inside one of the other three standard headers you've included, so the bug goes unnoticed. | |
Re: [QUOTE]Are there any known pitfalls in using fread ?[/QUOTE] It's comparatively awkward for reading string data. | |
Re: [QUOTE]I have written a stack to hold int's before, but never to hold nodes(or whatever it needs to hold...pointers?)[/QUOTE] You'd be holding pointers, and it's really no different from integers in how you use the stack: [code] TNode *stack[64]; int top = 0; [/code] I assume you're implementing an iterator-based … | |
Re: It's very rare when one absolutely [i]needs[/i] to keep everything loaded at the same time. I'd recommend changing your logic so that you only need to keep a few records in memory at once. | |
Re: Define what you mean by "string", because the whole file can be a string, each line can be a string, each word can be a string (for various definitions of "word"), to name three common needs. | |
Re: [QUOTE=james85]hi i would like u to tell me if i can make a random function to choose between four numbers and only them(-1 , 1 , -10 ,10)[/QUOTE] Yes, you can. Quite easily, in fact: [code] int a[] = { -1, 1, -10, 10 }; int choice = a[rand() % … | |
Re: Start by learning how to calculate a factorial. Then translate that to code. Finally, do that on every value from N to M. Seriously, have you tried [I]anything[/I] yet? | |
Re: Oddly enough, I posted a [URL="http://www.daniweb.com/code/snippet285300.html"]very basic memory pool[/URL] just the other day that does exactly what you're trying to accomplish. You might find it helpful. | |
Re: [QUOTE]Why is it not acting correctly?[/QUOTE] Probably because your length parameter is shy by one. Try not subtracting 1: [code] memcpy(temp_str, suf_arr[j].word+1, suf_arr[j].len); [/code] You still want to copy the null character, after all. | |
Re: [QUOTE=CppFTW]Hi, I was wondering if the compiler Visual C++ is smart enough to optimize code like this: [CODE=C++]string temp = "abcd"; string temp2 = "hahaha"; string temp3 = temp + temp2;[/CODE] "temp + temp2" can be replaced by "abcdhahaha" [/QUOTE] Actually, Visual C++ is smart enough [I]not[/I] to optimize in … | |
Re: You don't close a thread. Ever. That can only be done by moderators. Why do you want to do this? | |
Re: [QUOTE]isn't it supposed to stop on 5 letters or at least don't memorize these plus letters?[/QUOTE] Why would it? You never told it to do anything of the sort. In fact, it's quite impossible to include those safety measures with the gets function. You simply invoke undefined behavior, and the … | |
Re: [QUOTE]what is wrong here...[/QUOTE] Side effects, my inquisitive friend: [code] int x = 2; cout<< SQR(x++) <<'\n'; cout<< x <<'\n'; [/code] x is incremented twice due to the macro being nothing more than a textual substitution. Thus the expanded macro is [icode]x++ * x++[/icode]. | |
Re: This reeks of homework, and nobody will do your homework for you. However, I'll offer some clarification where I feel the questions are incorrect. [QUOTE]explain with suitable examples the advantages these [I][container classes][/I] give to the programmer over a procedural language such as C.[/QUOTE] This question exhibits a common misconception … | |
Re: You'll need to hook the keyboard at a low level to manage this. I'd suggest studying software key loggers for ideas. However, generally this kind of functionality is either unnecessary or malicious. Why do you want to process key strokes when the program is inactive? | |
Re: There are a number of ways to do it. Here's one: [code] #include <iostream> #include <string> int main() { using namespace std; string text; int nl = 0; cout<<"Press enter twice in a row to quit: "; while (nl < 2 && getline(cin, text)) { if (text.empty()) { ++nl; } … | |
Re: [B]>is their any body tell me the Difference between int* a; and int *a; ?[/B] From a language standpoint there's no difference. However, placing the asterisk by the variable makes more sense when you have multiple variables in a declaration: [code] int *p, *q; [/code] The reason this makes more … | |
Re: [QUOTE]I wonder why the following code work.[/QUOTE] It doesn't. The recursive calls fail to fix the subtree: [code] if(root->data>item) root->left = insert(root->left,item); else if(root->data<item) root->right = insert(root->right,item); [/code] | |
In answer to a coworker's question today about memory management today, I wrote the following code. It's an implementation of the gets function that accepts an infinite length string (bounded only by the heap) and [i]does not[/i] force the caller to free the resulting pointer. I figure that it's a … | |
Re: Good luck. Come back when you have a specific freaking question. :icon_rolleyes: | |
Re: [QUOTE]if i press anything else the program prints me the message twice[/QUOTE] Because there are two characters that don't match your condition in the stream. Run your test again and count how many keys you press. I bet you'll discover that one of them is the Enter key. | |
Re: [QUOTE]am seriously ready to pay a reasonable amount for this... around $20[/QUOTE] Daniweb is not a programmer rental service. Offering to pay someone to do your homework is the kiss of death around here. [QUOTE]i need to submit tomorrow.[/QUOTE] Congratulations, you've just gotten a lesson in time management from the … | |
Re: [QUOTE]How can i make sscanf() skip all whitespace characters?[/QUOTE] It's awkward for string data. You might be better off manually extracting the data you want. [QUOTE]eg.->@Solomon Islands ,i need "Solomon Islands" in one string[/QUOTE] The boundary characters matter. I assume the string starts with '@', but if it ends with … | |
Re: popen isn't a standard C++ function, but you'll typically find it as an extension in <cstdio>. | |
Re: This solution isn't uncommon. Last I heard, a stack of Mac Minis made for a decent load balanced server farm (as opposed to the usual career as a doorstop). | |
Re: [QUOTE=cscgal;1222646]> That being said, we are launching a new design for the site in about a month. I will give it a try at first, not using a modal, and see if all of the activity stats drop off. So the new design has been up and running without the … | |
Re: [URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046380353&id=1044780608"]Clicky[/URL]. | |
Re: [QUOTE]How do I code for various column widths?[/QUOTE] By using an appropriate data structure, reading each line as a whole, and then parsing out the columns. This is C++, so a vector of vectors or something similar would be far less awkward than a dynamic table. As for parsing the … | |
Re: Data structures implemented [I]using[/I] the STL, or implementing the STL itself? | |
Re: [QUOTE]however neither of those are C++ they are part of the C standard library and C++ provides the same functionality through the use of stringstreams.[/QUOTE] Just chiming in with a minor correction. atoi and strtol are most certainly C++. You shouldn't buy into the "pure C++" BS that encourages one … | |
![]() | Re: This reeks of homework. Please prove that you've tried to solve the problem if you want any help. Being fed an answer doesn't teach you anything except how to be helpless. |
Re: I think you're confused about how the insert member function works for the vector class. You'd probably be better off simply using the overloaded subscript operator: [code] productMap[prod->GetCode()] = prod; [/code] [QUOTE][CODE]static map<string, ProductLine*, less<string> > productMap;[/CODE][/QUOTE] [ICODE]less<KeyType>[/ICODE] is already the default predicate, you don't need to specify it unless … | |
Re: [QUOTE][CODE]getline(cin, line);[/CODE][/QUOTE] You're still pulling from cin. Change that to be your file stream: [code] getline(fileIn, line); [/code] |
The End.