436 Posted Topics
Re: Distance between the two strings? Do you mean the Levenshtein distance or something else? | |
Re: When you say bytes 15-18, is that the plain text or the cipher text? | |
Re: That would happen if you do this: [code] C:\> tcc Sample1.c C:\> tcc Sample2.c [/code] The linker errors because those two calls to tcc are separate. They both try to compile and link the file, but there is no definition of f1 when compiling and linking just Sample2.c. To get … | |
Re: If the two strings are not sorted, the 'best' way depends on what trade off you want to make. If you want to have a small memory footprint but slower algorithm your way is fine. If you want to have a faster algorithm at the cost of more memory, two … | |
Re: Start by loading the DLL with the [URL="http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx"]LoadLibrary[/URL] function. Then if the name you want is in the DLL's export table, you can call [URL="http://msdn.microsoft.com/en-us/library/ms683212(VS.85).aspx"]GetProcAddress[/URL] to get a handle to it. Here is an [URL="http://msdn.microsoft.com/en-us/library/ms686944(VS.85).aspx"]example[/URL] program that does everything. | |
Re: [QUOTE]I have a function under Base class and at the definition tine of this base class function I need to call another function which is define under the Derived class. how to do this??[/QUOTE] Make the method virtual and protected in the base class, then override it as public in … | |
Re: [QUOTE]How could I modify this so that when I edit a file and save it, it won't have to go through about renaming it and saving it again as if it is a new file?[/QUOTE] Most files are too variable to edit in place. Here are some guidelines for working … | |
Re: Flip your first thought around. If Scan has a pointer to a Scanner, the constructor can take an argument of [ICODE]this[/ICODE] from the Scanner object generating the Scan object: [code=cplusplus] class Scanner; class Scan { Scanner *_scanner; public: Scan(Scanner *scanner): _scanner(scanner) {} }; class Scanner { public: Scan GenerateScan() { … | |
Re: [QUOTE]Is this array initialization static or dynamic?[/QUOTE] C++ does not allow an array with a size that is not constant. If your compiler compiles that declaration and it runs, then the documentation will tell you how it works. I assume it has the same behavior as an array created with … | |
Re: There is not a portable way to set a window title. The best you can do is have something like a appsys.h header with all of the non portable stuff: [code=cplusplus] #ifndef APPSYS_H #define APPSYS_H bool ChangeConsoleTitle(const char *title); #endif [/code] [code=cplusplus] #include <windows.h> #include "appsys.h" bool ChangeConsoleTitle(const char *title) … | |
Re: Why do you want an array? The string class will work for both sides of the encryption: [code=cplusplus] int main() { string word, dword; // read a word for (string::size_type x = 0; x < word.length(); ++x) { dword += Crypt(word); } cout << word << '\n' << dword << … | |
Re: NRU is a caching algorithm based on time. Cache some data and when the data is used set a flag bit. At regular intervals, check the flag bits and deallocate the memory for any of the data where the bit is not set. NRU means not recently used inside the … | |
Re: First I get attacked for not being perfect right out of the gate. Now I get attacked for fitting in. What do you want from me? :confused: | |
Re: I guess this is homework, but if it is not, the library already has this stuff: [code=cplusplus] #include <algorithm> #include <iostream> #include <iterator> #include <set> #include <string> using namespace std; // use basic_string<T> to allow any char type template <class T> basic_string<T> Intersection( const basic_string<T>& a, const basic_string<T>& b) { … | |
Re: [QUOTE]you wont get any benefits from it and i dont even see a specific use[/QUOTE] I think it is a great way to explain the simplicity of C++. You will have to fight off the newbies wanting to learn if you show them the clear and intuitive code that can … | |
Re: [QUOTE]Is there ANY standards compliant way to get unbuffered input from the console without the characters being automatically displayed?[/QUOTE] Short answer, no. The console does its own buffering, and then C++ does another level of buffering for performance. [U]You can change C++'s buffering, but that only affects performance[/U]. By the … | |
Re: Find out what processes are taking up all of your physical memory and kill them or increase your physical memory. Dipping into virtual memory too much is a bad thing because it is much slower than real memory. You can increase the virtual memory space, but that's probably just a … | |
Re: [QUOTE]What is problem with memory occurs here?because the code will run fine>[/QUOTE] It is called a memory or resource leak. The memory you allocated from the first call to malloc is never freed, and for the rest of the program it will stay allocated and cannot be used anymore because … | |
Re: Why not change the locale to something that uses ',' as the radix character? Then you don't have to do any mumbo jumbo with strings: [code=cplusplus] #include <iostream> #include <locale> #include <sstream> using namespace std; int main() { istringstream is("12,34"); double a = 0; is.imbue(locale("german_germany.1252")); is >> a; // will … | |
Re: Code guards will work everywhere, but [ICODE]#pragma once[/ICODE] will only work if the compiler supports it. What's worse, one compiler might define [ICODE]#pragma once[/ICODE] to do the same thing as code guards and another compiler might define it to do something completely different. Your code would break on the second … | |
Re: [QUOTE]Even the delete operator is executed, the last two output statements are working same the first two output statements.. How is this possible...????????????????? [/QUOTE] When you free memory, it may or may not be reused immediately for something else. If it is not reused, you can still access the pointer … | |
Re: [QUOTE]Isn't the memory released automatically when the program ends?[/QUOTE] Yes and no. It depends on how your OS handles processes, but unless you work with some obscure or legacy systems, it is pretty safe to assume that when the program ends, all heap memory allocated to the process is freed … | |
Re: [QUOTE]I want to not see any warnings at all when I build.[/QUOTE] I haven't seen many warnings that were so asinine they could be completely ignored. Disabling warnings just so you can get a clean compile is not a recommended practice because fixing them almost always makes your code better. … | |
Re: [QUOTE=tazboy;919382][CODE]if ( infile ){ list = read_file( &infile, &lines ); infile.close(); }[/CODE] I did this and I still get the same result. When I cout << infile I get an address the first time and 0 the next time.[/QUOTE] Ancient Dragon already said you needed to clear the errors too. … | |
Re: [QUOTE=Ancient Dragon;919847]>>char EVENT_NAME; That only declares a single character. you need an array, such as [icode]char EVENT_NAME[255];[/icode] or better yet [icode]string EVENT_NAME;[/icode][/QUOTE] Please remember that if you use an array with operator>>, you also need to lock the upper limit so that cin does not overflow the array: [code=cplusplus] char … | |
Re: [QUOTE]in order to be able to overload an operator<<,it must be declared as the friend of the class.[/QUOTE] Only if the overloaded operator needs access to the private or protected members of the class. If you only touch the public interface, the operator does not need to be a friend: … | |
Re: There is not a short and easy way to do that. If you need to search your variables for matching values, then they're related enough to put in an array: [code=c] int a[] = {4, 2, 4, 4}; [/code] And if you need to keep the names, it's only slightly … | |
Re: If all of the fields have an overloaded copy constructor or assignment operator, or if they are built in types, you can just do assignments of all fields and everything should work right: [code=cplusplus] // use copy constructors and initialization CMatrix::CMatrix(const CMatrix& m) : _s_row(m._s_row), _s_col(m._s_col), base_mat(m.base_mat) { // all … | |
Re: It looks like you want a 2D array: [code=cplusplus] int P[] = { {0, 1, 1, 2}, {0, 3, 1, 0} }; for (int x = 0; x < 2; ++x) { for (int y = 0; y < 4; ++y) cout << P[x][y] << ' '; cout << '\n'; … | |
Re: This might help: [code=cplusplus] #include <iostream> using namespace std; int main() { const int size = 5; int a[] = {1, 2, 3, 4, 5}; int k = 0; for (int x = 0; x < 13; ++x) { cout << x << ": " << a[k++ % size] << … | |
Re: You are not allocating any memory that needs to be freed. You are using FILE pointers, so you need to call fclose() on each one, but that's all. Can you be more specific about what the problem is? | |
Re: [QUOTE][CODE] DynStack<double> doubleStack(); DynStack<float> floatStack(); [/CODE][/QUOTE] C++ syntax is kind of weird here. The compiler thinks you are trying to declare two functions, not instantiate two objects. For named objects, the default constructor does not need parentheses, and the syntax no longer looks like a function: [code=cplusplus] DynStack<double> doubleStack; DynStack<float> … | |
Re: The method is marked as const, so calling find on DoubleValues will use the overload that returns a const_iterator. You can't assign a const_iterator to an iterator, but because the method is const, it should be safe enough to change the iterator like this: [code] bool OrientedPoint::getDoubleValue(const std::string &ValueName, double … | |
Re: The overload is not needed. As long as the function parameter is a const reference to string, you can pass a string constant and it will become a string object. Libraries usually have the overload to avoid the cost of constructing a new string object, but it is not required. | |
Re: How about a list of objects that represent the data: [code=csharp] class Cost // needs a better name { public string Code { get; private set; } public string Description { get; private set; } public double Amount { get; private set; } public double ExchangeRate { get; private set; … | |
Re: [QUOTE]i would like to ask if this method should be called after ever cin statement?[/QUOTE] For anyone else reading, the method in question is [URL="http://www.daniweb.com/forums/thread90228.html"]here[/URL]. This thread used to be a post in that thread. operator>>() is the problem child here. It works something like this: [code=cplusplus] // beware: pseudo-code … | |
Re: [URL="http://www.newty.de/fpt/index.html"]Function pointers[/URL]. | |
Re: [QUOTE]This is just copied from an example, so I don't know exactly what it means. The only thing I actually know is that the word 'export' is defined.[/QUOTE] [ICODE]__declspec(dllexport)[/ICODE] is the magic incantation to add a name to the export table of a DLL. [ICODE]extern "C"[/ICODE] is C++'s way of … | |
Re: Any tutorial on the basic language will cover loops and arrays. Do you have more specific requirements for the program? It is hard to help with something vague like 'loops and arrays'. | |
Re: That's a lot of stuff to look at. Can you boil it down to something small enough to post in code tags? | |
Re: [QUOTE]I want to add a string of numbers(e.g 9999) which are stored in a text file.[/QUOTE] Are you just adding the digits? If so then for each character that is a digit, you can subtract '0' from it to get the integer value: [code] '0' - '0' = 0 '1' … | |
Re: 2D array arguments need a size for all but the first dimension. If you don't know the size until run time, or the function has to take different sized 2D arrays, you can use a pointer to a pointer instead. Then the calling code can either allocate memory to a … | |
Re: [QUOTE]it seems to me if you don't use pointers then you never have memory leak type problems...[/QUOTE] I wish that were so. :( Raw pointers are dangerous, and that's why smart pointers and RAII are so important. Even if you use the troublesome auto_ptr, your leak problem can be fixed: … | |
Re: [QUOTE]>I just thought syntactically that it was incorrect No it isn't. Syntactically it is fine but it is deprecated.[/QUOTE] Just because you don't like a feature or it was inherited from C doesn't make it deprecated. ;) To the best of my knowledge, (void) parameter lists are not deprecated. Please … | |
Re: [QUOTE]1) This is exactly what I'm encountering. I googled for that but none of those posts talked how to do this: member function B::fb makes a call to _beginthreadex with thread function which is a member function ( A::fa ).[/QUOTE] Google probably doesn't talk about it because that is not … | |
Re: [QUOTE]Wouldn't a simple If Not Defined wrapped around the include solve the "conflict"?[/QUOTE] Yes. Even better is the usual convention of wrapping everything in the header with a conditional compile test: [code=cplusplus] #ifndef HEADER_H #define HEADER_H // header contents #endif [/code] Then it doesn't matter how many times the header … | |
Re: Without more code to look at, I can only guess. But my guess is that he didn't include the right header for strdup and casted the result to silence his compiler's warnings about it. | |
Re: This is what sscanf was born to do: [code=c] #include <stdio.h> int main() { const char *p = "TAGNAME_C123_V45_S67_M89"; int c, v, s, m; if (sscanf(p, "%*[^_]_C%d_V%d_S%d_M%d", &c, &v, &s, &m) == 4) { printf("C=%d\nV=%d\nS=%d\nM=%d\n", c, v, s, m); } return 0; } [/code] | |
Re: You can declare a function without defining it if you replace the curly brackets and code with a semicolon: [code=cplusplus] void Menu(); void McDonalds() { // ... } void Menu() { // ... } [/code] |
The End.