2,898 Posted Topics
Re: Instead of bothering yourself with doing copies of backup files with the tilde mark. I would suggest you just use a subversion control system. I recommend [URL="http://git-scm.com/"]Git[/URL]. At any time, you can retrieve the entire history of the modifications to any of your source files ("diff" style). That's very easy … | |
Re: >>#2 You cannot use the == operator for comparing C-strings (arrays of chars), this will only compare the pointer values. To compare the actual C-strings, you need to use the [URL="http://www.cplusplus.com/reference/clibrary/cstring/strcmp/"]strcmp[/URL] function. For the rest, I don't understand the questions or what you want. | |
Re: Just make the handler for the click button event in the Interface class, and then call a function of the DAQCycle class, and pass it the "this" pointer of the Interface object. | |
Re: This: [CODE] l.pHead=p.pNext; p.pNext=NULL; Thus, l.pHead=NULL; [/CODE] is wrong. You are thinking about the = operator as if it was like in mathematics. When you write "a = b" in C++ (and in almost any programming language), it means that you copy the value of b and assign it to … | |
Re: This is a question that comes up from time to time on forums on C++. And, I'm convinced now that there is no way to do this. I hope I'm wrong, but I think there is little chance. | |
Re: Read [URL="http://www.parashift.com/c++-faq/references.html"]this[/URL]. | |
Re: To store the prices as doubles, just make them doubles. Declare your price pointer as: [CODE] double * price; [/CODE] And allocate an array of doubles: [CODE] price= new double[items]; [/CODE] You don't have to change anything else (that I can see). | |
Re: If your problem corresponds to iamthwee's interpretation, then his solution is appropriate. If your problem is that you want to create a vector of arbitrary size where each element is one of the four color-strings, picked at random. Then, a simple solution is to map each color to a number … | |
Re: Well, pretty much everywhere in the code, you use a single < where you need two (outputting with streams). That will fix your problem. And you also need to #include <cstring> to get the strlen function. | |
Re: >> I have not given a size to the vector.Could it be because of that? Well, if your vectors are empty, how could you expect to be able to access elements of them? I think people reading your example assumed it was not real code, just an example of the … | |
Re: What Narue says is entirely correct. >>WHy does the loop terminate after 13 iterations? Your stack-frame will look like this: 8 bytes for the char-array (ca) (aligned at 4 bytes, since it needs 5 bytes, it will take up 8 bytes as the smallest multiple of 4 bytes), and 4 … | |
Re: Or maybe something along the lines of: [CODE] #include <iostream> #include <fstream> #include <string> using namespace std; int main() { ifstream infile("input.txt"); ofstream outfile("output.txt"); int value; while(infile >> value) { char mod_val = (--value) % 52; outfile << string(value / 52 + 1, (mod_val < 26 ? mod_val + 'a' … ![]() | |
Re: Don't bump a three year old thread to ask an unrelated question. If you can't find the answer to your question by looking on Daniweb or on the web at large, then create a new thread for your question. And to answer, to convert a string to a float, you … | |
Re: Well, first, your error about printing the object's content is easily solved. Your function "getVehicleType" prints the values already, so you just need to call it, don't insert it into a << operator statement, just call it: [CODE] //cout <<"id "<< vehicles[i]->getVehicleType() <<endl; //ERROR! vehicles[i]->getVehicleType(); //OK! [/CODE] Now, about the … | |
Re: As for the libraries, I would recommend to use well-established cross-platform libraries. For your purposes, SDL and/or OpenGL are candidates of choice. Start with SDL and add OpenGL when you want to take your graphics one step further. Programming a graphics computer game is a lot different from simple console … | |
Re: In the simplest possible way, it means: Dear mister compiler, In this place (or scope), I would like to be [ICODE]using[/ICODE] this [ICODE]namespace[/ICODE] that they call [ICODE]std[/ICODE]. This would really help me because I won't have to qualify everything with [ICODE]std::[/ICODE] in the remainder of this scope. Thank you. And … ![]() | |
Re: You will find the reference on std::map [URL="http://www.cplusplus.com/reference/stl/map/"]here[/URL]. A simple example that basically fits your problem is this: [CODE] #include <iostream> #include <string> #include <map> using namespace std; int main() { map<string,string> tags; //create the list of tags: tags["-color"] = "c"; tags["-weight"] = "w"; tags["-size"] = "s"; //... while(true) { … | |
Re: [CODE] $ sudo apt-get install linux-source [/CODE] From a Linux terminal, of course. | |
Re: A forward-declaration simply announces that a class with that name will be declared later. But to be able to use any of the members of the class (including constructor/destructor or any data members or member functions), the compiler has to have seen the declaration of the class, not just its … | |
Re: You need to be consistent with the const-qualifier, either you have a const function that returns a const reference or you have a non-const function that return a non-const reference, but usually, you can just do both: [CODE] const vector<double>& getDensity() const {return density;} vector<double>& getDensity() {return density;} [/CODE] The … | |
Re: This "pre-declared class", as you call it, is what programmers call a "forward-declaration". A forward-declaration is useful when you need two classes to depend on each other (which would otherwise not be possible). Here is a simple example: [CODE] struct DogOwner { Dog fido; }; struct Dog { DogOwner master; … | |
Re: The operation: [CODE]if(prompt2 == "ADD", "ADDITION", "+", "PLUS")[/CODE] will not do what you expect. It will always evaluate to true, regardless of the value of prompt2. This is because it uses the comma operator. The comma operator has the effect of evaluating each elements between commas and return the value … | |
Re: >>How can I be a programmer who can understand the codes and writes neat and clean code. You learn by experience, like anything else, practice makes perfect. If you are comfortable with the syntax of a language and the general logic of programming, then the next step is usually to … | |
Re: add the serialization library to the linking, directly. Not just under library directories, but also as a library to be linked. Find the boost_serialization library (either libboost_serialization_..a or boost_serialization...lib). Boost has some automatic linking of some required libraries, but this system only works for some compilers (e.g. MSVC) but not … | |
Re: You need to #include <string>. The problem is because iostream declares the string class via some inclusions under-the-hood, but it does not include the << operator for the string. At least, on some implementations, this is what happens, on others, it includes both the string class and its << operator, … | |
Re: You have fell pray to the [URL="http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.14"]"static initialization order fiasco"[/URL]. Read the linked article, and you will understand the problem and read about the solution. | |
Re: Well, you are going to need to do simple input/output with the user and with a file. For user input/output on the console, you will need <[URL="http://www.cplusplus.com/reference/iostream/"]iostream[/URL]>, with cout for output and cin for input. See [URL="http://www.cplusplus.com/doc/tutorial/basic_io/"]this tutorial[/URL]. Then, you will need to use [URL="http://www.cplusplus.com/reference/string/string/"]std::string[/URL] to manipulate strings, to be … | |
Re: >>"to use a hash table to sort" I'm not an expert on hashing, but this statement seems to make little sense to me. Hash tables are rarely used to sort anything (which requires a hash function that respects the ordering of the keys, which typically makes it very difficult to … | |
Re: I do agree that C and C++ are two distinct languages and, in general, you can just learn one (C++) directly. It's not like C is a stepping stone to learning C++. If you want to learn C++, then you don't need to learn C first, that's just a waste … | |
Re: In your CManager class, you should have a data member like: [CODE] std::vector<CWorker> m_Workers; [/CODE] In your CWorker, as suggested, you should have a constructor like: [CODE] class CWorker { //... public: CWorker(const char* aName,int aSalary = 0) { m_wName = aName; m_wSalary = aSalary; }; [/CODE] And, your addWorker … | |
Re: This code: [CODE] myclass Object("some_file.xml"); if (Object.error_val == -1) delete Object; [/CODE] Is invalid. You cannot "delete" things that are allocated on the stack. "delete" can only be used to delete things that were allocated with "new", as so: [CODE] myclass* Object = new myclass("some_file.xml"); if (Object->error_val == -1) delete … | |
Re: Is it "stack<int>" or an array? Because stack<int> is a standard container (adaptor), named [URL="http://www.cplusplus.com/reference/stl/stack/"]std::stack[/URL]. It is very possible that the author sloppily said it is an array, because many C++ programmers (including myself) will often forget that the general term "array" (which can mean any kind of homogeneous data-set) … | |
Re: I think that the first thing to do is to get a container for all the unique words that describe numbers (not compounded). If in English, that's not very hard or very many. The unique numbers run from 0 to 19, then 20-30-40..90 and 100-1000-1000000.., everything else is a compounded … | |
Re: You have a semi-colon at the end of line 88, which should not be there. Because this is how the compiler interprets things: [CODE] void myFunction(); //declaration of "myFunction" void myFunction() //definition of "myFunction" { //... }; void myFunction(); //declaration of "myFunction" { //ERROR: what is this { ? You … | |
Re: The error comes from lines 105 and 114, you should not multiply the numt by 3. The "count" given to the glDrawArrays is the number of vertices to draw, so it should be numt. As so: [CODE] glDrawArrays(GL_TRIANGLES, 0, numt); [/CODE] Also, your class is missing several very important basic … | |
Re: The is a complete [URL="http://msdn.microsoft.com/en-us/library/aa364418(v=vs.85).aspx"]set of functions[/URL] from WinAPI to "browse" the folders for the files. Personally, I think they are crap (annoying and kind-a hard to use). But, that is what the Open/Save file dialogs use in MFC or win32. I would recommend you use [URL="http://www.boost.org/doc/libs/1_47_0/libs/filesystem/v3/doc/index.htm"]Boost.FileSystem[/URL], it is much … | |
Re: In C++, we don't tend to use C style arrays, it is more common and easier to use standard classes that can hold arrays. In this case, you can use either std::vector<double> or, if you have a reasonably recent compiler, std::array<double,2>, as so: [CODE] #include <iostream> #include <array> using namespace … | |
Re: [URL="http://oss.sgi.com/projects/inventor/"]OpenInventor[/URL] is a pretty useful tool to make OpenGL programming easier by providing lots of built-in functionality.But there are [URL="http://www.opengl.org/resources/libraries/higherlevel/"]many others[/URL]. | |
Re: As for the static_cast vs dynamic_cast, the only difference in effect between the two is that the dynamic_cast does a run-time check to see if the cast is possible. In other words, if you pass a pointer to class A, and try to cast to a pointer to B, then … | |
Re: To give a more useful answer, that is, knowing what typically could happen when you delete a pointer twice might help you recognize the situation if you see those symptoms. So, although it is undefined behaviour, as arkoenig mentioned, there are a number of things that would typically happen if … | |
Re: Because the date in a "[URL="http://www.cplusplus.com/reference/clibrary/ctime/tm/"]tm[/URL]" structure is counted from year 1900. Which means that 2011 is stored as 111. Generally, if you want to print a string from a time_t structure, use the function "[URL="http://www.cplusplus.com/reference/clibrary/ctime/ctime/"]ctime[/URL]". Or, to convert from "tm" structure, use "[URL="http://www.cplusplus.com/reference/clibrary/ctime/asctime/"]asctime[/URL]" or "[URL="http://www.cplusplus.com/reference/clibrary/ctime/strftime/"]strftime[/URL]" for special formatting. | |
Re: @tkud: What you are describing is what I call "derived class intersection", which is a very classic misunderstanding of what base classes are useful for. I suggest you revisit your understanding of the topic. Learn from the saying "Inherit not to reuse, but to be reused". @tiredoy: The main purpose … | |
Re: Taking your code to the 21st century, and doing correct indentation (which helps understanding the code), we get: [CODE] #include <fstream> #include <iomanip> #include <iostream> #include <algorithm> #include <conio.h> using namespace std; int amountRead = 0,max_read = 99; const int maxn = 4200; float array[maxn] = {0.00000}; void getfloat(); void … | |
Re: No. The best algorithm is to check that all off-diagonal terms are equal (within a tolerance). And, there are (N^2 - N) / 2 checks to be done, which is of order O(n^2). | |
Re: cout is in the std namespace. You need to either qualify it fully, like so: [CODE] #include <iostream> int main() { std::cout << "Hello World!" << std::endl; }; [/CODE] Or, you can issue a "using namespace std;" statement, as so: [CODE] #include <iostream> using namespace std; int main() { cout … | |
Re: I may be wrong here, but isn't the CPM simply solved by formulating the problem as an Action-On-Arc (AOA) graph. Then, you just solve for the solution using a standard shortest-path algorithm (evidently, you multiply the costs by -1 to get a longest-path algorithm). You can, for instance, use the … | |
Re: >> it looks to me more like a function Or like the construction of an object, which it is. If I have a class named "my_class", I can create an object of that class with "my_class()", which means the object is default-constructed and doesn't have a name (a temporary). So, … | |
Re: Use [URL="http://www.cplusplus.com/reference/stl/vector/"]std::vector< std::string >[/URL]. | |
Re: I think that your intent with the dm_energy_vec class was to just make an alias for the vector<float> type, this can be done with a typedef, as follows: [CODE] typedef vector<float> dm_energy_vec; [/CODE] Then, all your code should work. If you actually want to make the dm_energy_vec class more complicated … | |
Re: >>You should write a beginner's tutorial on C++0x for Daniweb. That will be a great way to promote this site. I can also contribute on some easier topics!!. That's a great idea! I think most advanced programmers can just look at the wiki or Bjarne's FAQ page, and totally understand … |
The End.