436 Posted Topics
Re: Is it set to start automatically or manually? | |
Re: Hash functions can handle more than just integers. The generic algorithms can hash any collection of bytes you give them: [code=cplusplus] unsigned int hash(void *key, int sz) { unsigned char *p = (unsigned char*)key; unsigned hval = 0; for (int x = 0; x < sz; ++x) { hval = … | |
Re: What is your canceling function supposed to do? | |
Re: [QUOTE]So q+1 is address immediately after the 50 elements but how does the type casting affects the output.[/QUOTE] Pointer subtraction takes the size of the type into account. If it's a pointer to char, the size is 1 and with 50 chars the result will be 50. If it's a … | |
Re: You could probably dig around and figure out what the problem is, but an easy first step is to reinstall/repair Visual Studio. Make sure the installation is clean before doing any crazy troubleshooting. It could just be a corrupt DLL or two. :) | |
Re: All strtok does is replace the delimiter with '\0'. If you skip over it, you'll find the rest of the string: [code=c] #include <stdio.h> #include <string.h> int main() { char s[] = "a|b|c|d|e|f|g"; char *tok = strtok(s, "|"); printf("%s\n%s\n", tok, tok + strlen(tok) + 1); return 0; } [/code] The … | |
Re: [QUOTE]2. In the above code snippet, when I define class Sampler as a local class, g++ shoots an error. Why is it that compiler works fine with vector vec3's declaration when class Sampler is global and shoots an error when Sampler is local to main?[/QUOTE] It is just one of … ![]() | |
Re: [QUOTE]Basically it comes down to this: If you don't either (1) prototype the function or (2) fully define the function prior to its use[/QUOTE] Simplify, my friend. :) A function definition is also a prototype, so you don't need to split them up. As long as there is a prototype … | |
Re: The tutorial tells you what to do to compile as Managed C++ instead of C++/CLI: [QUOTE][B]Note [/B]In Visual C++ 2005, you must add the common language runtime support compiler option [B](/clr:oldSyntax)[/B] to successfully compile the previous code sample as Managed C++. To add the common language runtime support compiler option, … | |
Re: Linked lists can be sorted just like arrays as long as you only use sequential access. Pick a sort algorithm that only looks at adjacent nodes at any given time and it'll work for lists. You don't need to monkey with links either, just swap the data. This is a … | |
Re: [QUOTE]On gcc compiler, 2nd and third printf() call taking value of i and j automatically.. but if in first printf() call ,i don't give i and j as argument then that prints garbage value.. can nyone explain it plz..[/QUOTE] It happens to work out that way with how printf and … | |
Re: [QUOTE]I'm a beginner and trying to convert this code in class.[/QUOTE] It's already a class. The only difference between struct and class in C++ is the default access rights. struct is public by default and class is private. [QUOTE]kindly do it for me.[/QUOTE] Sorry my friend, but it doesn't work … | |
Re: [QUOTE]Is there a 'z' involved, as in the total number of groups?[/QUOTE] z can be calculated using x and y, but having an actual z makes it harder to handle an x that isn't perfectly divisible by y. | |
Re: What don't you understand? I could write pages and pages explaining what's happening, but that won't help as much as a pointed answer to a pointed question. ;) | |
Re: Except for deleting line 15, what Ancient Dragon wants you to do will make your code more portable. That's a good goal, but you have a real problem to fix first: integer overflow. p, r and t can't be very big before multiplying them together will overflow an int, and … | |
Re: search is a standard name declared in the <algorithm> header. It's a very bad idea to use standard names even if you don't include the header because other standard headers could include it. Try capitalizing your class from search to Search, or put it in a namespace. | |
Re: Assuming that [ICODE]return B;[/ICODE] should be [ICODE]return ptr;[/ICODE], there shouldn't be a segmentation fault. The memory doesn't go away until your code deletes it. As long as you have a pointer to the memory, it's safe to access. But if you don't ever delete it, that could cause a memory … | |
Re: [QUOTE]I have no clue as to how to start or even where to start.[/QUOTE] Then you're thinking about it the wrong way. Whenever you get overwhelmed with a problem, the problem is too big and needs to be broken down into smaller problems. Instead of doing everything, just open and … | |
Re: How huge is huge? What problem are you having? | |
Re: It's hard to help you fix your code if you don't show it. ;) | |
Re: [ICODE]Assembly::GetExecutingAssembly()->Location;[/ICODE] will give you the full path of the running program. The 'file date' isn't specific enough. Do you want the creation time, the last read, last write? But the File class has that stuff: [code=cplusplus] String^ path = Assembly::GetExecutingAssembly()->Location; DateTime^ fileDate = File::GetCreationTime(path); [/code] | |
Re: I generates undefined behavior. [ICODE]new[/ICODE] goes with [ICODE]delete[/ICODE] and [ICODE]new[][/ICODE] goes with [ICODE]delete[][/ICODE], you can't mix them. But in practice it will cause a memory leak for the first delete, and probably also a crash when you try to delete the second time. | |
Re: The string is only a palindrome if the characters match all of the way through. Your flag should be changed in the loop if the test fails, and you can also break from the loop because there's no need to continue checking a failed palindrome: [code=c] int different = 0; … | |
Re: Stupid question: if it works for set<>, why not use set<> instead of hash_set<>? I know it's the difference between a balanced BST and a hash table, but if set<> isn't too much slower you should use the way that works right now instead of fix something broken. | |
Re: [QUOTE][CODE]return *output;[/CODE][/QUOTE] That line is really the whole problem. [ICODE]*output[/ICODE] is not a pointer to char, it's a char. You're also trying to return a pointer to a local array. When the function returns, the local array goes bye bye and you can't use a pointer to it anymore. Try … | |
Re: Take the pattern out of it and do a simple triangle: [code] F FF FFF FFFF FFFFF FFFFFF [/code] You can add another variable that counts down without changing how the loops work in the triangle code: [code] for x = 1 to 6 for y = 0 to x … | |
Re: [QUOTE]Yeah thats exactly what i wanted,sad to know not possible[/QUOTE] What you want is called reflection. C++ has a very limited type of reflection in the RTTI stuff, but it doesn't work for variable names because variable names are lost during compilation. You have to map input strings to objects … | |
Re: [QUOTE]but i thought it would be easier if there is one simple way doin like a function or somethin.[/QUOTE] You can write your own function to do it. :) But doing it in a general way is not as easy as you thing. Removing all spaces is easy but leaving … | |
Re: Tutorials only go so far. You need a [URL="http://www.amazon.com/Programming-Windows%C2%AE-Fifth-Microsoft/dp/157231995X"]good book[/URL] and a [URL="http://msdn.microsoft.com/en-us/library/default.aspx"]comprehensive reference[/URL]. | |
Re: [QUOTE]1. Difference between memory allocation of local and global (or other static variables)....? (or why i cant initialize a global variable more than once outside main and all other functions) 2. Holes in structures, and structures and pointers. 3. Deep concepts in pointers, objects, classes.....i mean relation between pointers and … | |
Re: I don't know what signal 368 is, but if the segmentation fault is happening in list::erase(), you can search for where you call it and stop there in a debugger to see what's up. Maybe you're passing list::end() or an invalid iterator as one of the arguments. | |
Re: [QUOTE]use string stream in general and use atoi if speed is an issue.[/QUOTE] That's close to my advice. But I say use strtol because atoi doesn't have any error handling capability. Boost:lexical_cast and Boost::numeric_cast are even simpler than ad hoc string stream code or robust strtol code, but you have … | |
Re: [QUOTE]I thought you were from USA, what nationality are you?[/QUOTE] Military service in the US hasn't always been voluntary. The draft only stopped around 1980. | |
Re: [QUOTE=dorkwad;903681]Hey,new to stl, in c array, we can declare an array like [CODE]int a[]={2,4,5,6,7,7}[/CODE] how can u do it for a vector without pushing back n times???[/QUOTE] C++0x has extended initializer lists, but current standard C++ doesn't allow it for the vector class without tricks like siddhant3s'. [URL="http://www.boost.org/doc/libs/1_39_0/libs/assign/doc/index.html"]Boost::Assign[/URL] can make … | |
Re: There is no point in understanding the output. It's [URL="http://en.wikipedia.org/wiki/Undefined_behavior"]undefined behavior[/URL]. The output could be different the next time you run the program. UB also makes the rest of the program undefined so you have to understand all of that craziness too. It's a waste of resources to understand UB, … | |
Re: [QUOTE]Why is it? I am probably missing something very simple here.[/QUOTE] Something subtle, yes. References are not pointers, even though internally they might be implemented using pointers. When you have a reference to an objects, members are accessed the same way as with regular objects. | |
Re: [QUOTE=tomtetlaw;902948]this is of topic but, how come the size of thing is called an operator if it takes a parameter?[/QUOTE] It doesn't take a parameter, it takes an expression as the operand. Expressions can be surrounded with redundant parentheses: [code=cplusplus] double d; float f; sizeof d; // no redundant parentheses … | |
Re: [QUOTE=tux4life;902898][URL="http://siddhant3s.googlepages.com/how_to_tell_rusted_cpp.html#SECTION00044000000000000000"]http://siddhant3s.googlepages.com/how_to_tell_rusted_cpp.html#SECTION00044000000000000000[/URL][/QUOTE] That link is really opinionated. [ICODE]using namespace std;[/ICODE] says that every name in the std namespace is available without having to prefix it with [ICODE]std::[/ICODE]. [ICODE]using std::{name};[/ICODE] says that only the specified name is available without a prefix. Without either of those, you have to prefix every instance of … | |
Re: [QUOTE]I need to write these to a binary file and in binary values (139 = 00110001).[/QUOTE] 139 in binary is 10001011. Are you using a different way of encoding the value as binary? I can show you how to get the bits of a value, but that won't help if … | |
Re: Open a text file for reading by making an object of the ifstream class. Once it's open and everything is good, you can use it just like cin. Objects of the ofstream class work the same way and can be used like cout: [code=cplusplus] #include <fstream> #include <iostream> #include <cstdlib> … | |
Re: [CODE]while (tryanother = 'y'){[/CODE] [CODE]if (tryanother = 'n')[/CODE] The equality operator is ==. The = operator is for assignment. Those two conditions are the same as these: [CODE]while ((tryanother = 'y') != 0){[/CODE] [CODE]if ((tryanother = 'n') != 0)[/CODE] | |
Re: [QUOTE]you need memset() to set a default value.[/QUOTE] memset() is not needed. You can do it without calling a function by using an initializer for the array: [code=c] int array[4][2] = {0}; /* init all elements to 0 */ [/code] | |
Re: [QUOTE]i couldn't understand the "." format...[/QUOTE] It's one of the new features to C. You can initialize struct members by name instead of by position: [code=c] struct test { int first; int second; int third; }; struct test a = {0, 0, 1}; /* Old way */ struct test b … | |
Re: I don't think that kind of thing can be taught. You just have to read code to see how other programmers did it and try out things for yourself. The more you do it the better you'll get at it. There's no 'right' way to design OO programs. Nobody can … | |
Re: [QUOTE]Next time, try to elaborate your point so that the other person can comment on it.[/QUOTE] Well, now you know how it feels to get negative rep you don't agree with. No chance to defend, just BAM, hit and run. [QUOTE]Linux is really a good designed OS.[/QUOTE] Linux is a … | |
Re: A binary operator is an operator like + or / that have two operands, one on each side. A unary operator is an operator that only has one operand: [code=cplusplus] a * b // binary true && false // binary -1 // unary !x // unary [/code] | |
Re: This is the essence of what you're doing: [code=cplusplus] #include <iostream> using namespace std; int main() { int *p[10]; int val = 5; for (int x = 0; x < 10; ++x) p[x] = &val; for (int x = 0; x < 10; ++x) cout << *p[x] << '\n'; val … | |
Re: [QUOTE]Did I do it right? the function doesnt seem to be returning anything[/QUOTE] The function doesn't return anything because the return statement is commented away. The function returns a junk pointer. I don't think strtok is the best way to do this because you don't have a good way of … | |
Re: So you can do things like [ICODE]a = b++[/ICODE] and [ICODE]a = ++b[/ICODE]. Chaining and combining expressions accounts for most of the weirdness in how operator overloading works. But you don't have to follow the conventions even though it's a good idea to stick to idioms that everyone expects. Your … | |
Re: [QUOTE]but my ans is always "password is wrong"[/QUOTE] Print both strings and eyeball them: [code=cplusplus] cout << ">" << passFromFile << "<\n"; cout << ">" << passFromUser << "<\n"; [/code] There's probably whitespace or something that makes the difference. |
The End.