466 Posted Topics
Re: As Jonsca said, you can't just display an image in C++ (well you can, but you wouldn't want to because you'd have to write a lot of complex code that has already been written by other people and packaged into a nice library). If you want something really easy to … | |
Re: You shoud test your `IsInt` function with "-1", which is also an `int` :o) | |
Re: Do you have to escape the angled brackets? So use `\<` and `\>` instead of `<` and `>`, respectively. | |
Re: I don't think you can easily do it in a portable way using simple standard library calls. I would look at boost::filesystem if I were you. | |
Re: The compiler-generated copy constructor isn't a special one - it's just a simple one that copies the member variable values from one object to another. When you declare a copy constructor like the one that you have, the compiler doesn't need to make a copy constructor, so it doesn't, you … | |
Re: `srand` doesn't generate a random number, it sets the seed for the random number generator. The `time` part is using the current time when the program is run as the seed. This effectively means that the seed is different for each run and the program will do different things each … | |
Re: Is there some confusion here? I thought that the OP was asking how the program could be made to save some data to a binary file, not how to compile it. Admittedly, the OP could do more to explain what the issue is and what they would like to do... | |
Re: i would look at using the Boost date time library if i were you. | |
Re: I don't know the answer but I do know this whole area is a real pain. I tend to try and use Qt's `QString` and let the Nokia guys worry about it :) | |
Re: Whenever you open a file to read or write, CHECK THAT IT OPENED! It's really easy to enter the wrong directory path or something. Do something like this: std::ifstream inFile( "test.txt" ); if ( ! inFile.is_open() ) { std::cerr << "Error! Failed to open file" << std::endl; return 1; } | |
Re: It's not necessarily a bad thing or a good thing; it depends on the situation. The thing that you have to remember is that if you change the header at all, then all the files that depend on that header are going to need to be re-built, which can lead … | |
Re: On line 7 you have the body of the code. What's in there? `std::bad_alloc` is thrown when no memory is available for the `new` operation. Can the loop `continue` without getting to the part when `delete` is called? If so, you may be running out of memory. Check the system … | |
Re: Reading in the file can be really fast (as it will be in the second example that you have). However, tokenizing the file will be slower. Have you tried a more C++ approach of using `istream_iterator` to read in and tokenize your file? Something like: int main() { // Open … | |
Re: I would use an `enum` value to express the geneder. If you haven't used `enum`s in C++ before, just Google it. Enums aren't very complicated; they're basically a way of giving a human-readable name to an integer value (in your case the values would represent genders). I would have something … | |
Re: It's a bit orthogonal, but have you looked at [boost::program\_options](http://www.boost.org/doc/libs/1_49_0/doc/html/program_options.html) before? It's really useful for doing this kind of thing and very simple too. | |
At work we have a large number of unit tests that try to alert us that we have made changes that have broken our code. Many of these tests work by evaluating functions under known conditions and comparing the result with the known result. The known result is acquired by … | |
Re: No, it means that it can't find the definition of a class that you're using. Is there a line before the first one shown here that says something like "Undefined reference to..."? | |
Re: I think that my answer would include a `ProductSet` class that stores all the products that ae read from the file. Since you might have several classes of product (all derived from `Product`), such as `Weapon`, `Tool`, `Clothing`, `Food`, etc. then your `ProductSet` class should probably use store the products … | |
Re: Of course it does. Try changing line 29 to `p1->display();` :) | |
Re: If you're using a `std::string` then you can use its `find` method, which returns `std::string::npos` if the character you're looking for isn't there. If you're using a `char` array then you can use `std::find` from the STL `<algorithm>` library: #include <algorithm> #include <iostream> int main() { // Make some char … | |
Re: `std::map` can take a *comparator* as one of its template arguments, so you just need to define you're own custom comparitor for pointers. If the thing that is pointed to has an `operator<` defined then you can make a one-size-fits-all template comparator: template< typename T > class pointer_comparator : public … | |
Re: You can read from a file in a similar was to the way that you read from user console input. You need to include `<fstream>`: #include <fstream> #include <iostream> #include <vector> int main() { std::ifstream my_file( "testFile.txt", std::ios::in ); if ( ! my_file.is_open() ) { std::cerr << "Error!" << std::endl; … | |
Re: You should do as gerard4143 says and use a loop to calculate your mean value. Even better, take than loop and put it in it's own function, something like: double calculateMean( int* arr, int size ); You should also be careful since your method of calculating the mean doesn't do … | |
Re: There are actual standard library functors to do these things for you, in `<functional>`. You can do things like: #include <functional> #include <iostream> int main() { int a = std::plus< int >()( 2, 3 ); std::cout << a << std::endl; return 0; } In general, you should try and use … | |
Re: There are techniques from bioinformatics to perform this kind of task. Try looking at [this](http://en.wikipedia.org/wiki/Sequence_alignment) | |
Re: You should make an attempt at the question yourself. If you have a specific problem with the code you've written, then maybe you can ask for help with those problems | |
Re: There are three books by Scott Meyers that I would definitely recommend: * [Effective C++](http://www.amazon.co.uk/Effective-Specific-Addison-Wesley-Professional-Computing/dp/0321334876/ref=pd_sim_b_1) * [More Effective C++](http://www.amazon.co.uk/More-Effective-Programs-Professional-Computing/dp/020163371X/ref=pd_sim_b_5) * [Effective STL](http://www.amazon.co.uk/Effective-STL-Specific-Professional-Computing/dp/0201749629/ref=pd_bxgy_b_img_c) Additionally, if you're considering making a career out of programming (in any language, not just C++), I'd also recommend [The Pragmatic Programmer](http://www.amazon.co.uk/The-Pragmatic-Programmer-Andrew-Hunt/dp/020161622X/ref=sr_1_1?s=books&ie=UTF8&qid=1332880833&sr=1-1). It has lots of very useful … | |
Re: If you just want to solve polynomials, then you could use an existing library (for example [GSL](http://www.gnu.org/software/gsl/manual/html_node/Roots-of-Polynomials-Examples.html) has polynomial solving). Of course, if this is some kind of assignment, then that probably won't help very much. In which case, you should post an example of what you have attempted so … | |
Re: boost string algorithms can help you out here. As well as boost lexical_cast. | |
Re: Make a [icode]std::ofstream[/icode] object (instead of an [icode]std::ifstream[/icode] object, as you would for reading in). Then use it just as you would [icode]std::cout[/icode] (don't forget to close the file when you're done) | |
Re: You need to allocate the memory for [icode]conductor[/icode]: [code] int _tmain(int argc, _TCHAR* argv[]) { struct node *conductor = new node; // Allocate memory add(root, 'a'); conductor->ch = 'l'; conductor->next = NULL; root->next = conductor; read(); return 0; } [/code] You have also used a lot of C-style syntax that … | |
Re: If this is an assignment for a class then the method you have is probably the right kind of way to go. However, if you're doing it for a project of your own, then you can do this in a couple of lines using STL algorithms: [code] // Make an … | |
Re: [QUOTE=greatman05;1782842]But this is the problem; I'm using member functions from the base class to modify the member variables of the derived classes. In other words, each dervied class has its own balance and I'm trying to modify the dervied class's balance. I can only do this with the base class … | |
Re: #ifndef is what you want to check if something has not been defined. Checking for the inclusion of a particular header will be depend on your compiler. you'll have to put some effort in to make it portable :-) | |
Re: You should make some new functions that do the printing for the different types that you want to print. For example: [code] void PrintValue( int x ) { printf(" %2d", x); } void PrintValue( double x ) { printf(" %2.2f", x); } template <typename T> void printArray(unsigned int x_sz, unsigned … | |
Re: For class templates, you usually can't split the code into a .h and .cpp file. Did you try putting all the code in the cpp into the header file? | |
Re: [QUOTE=nunca;1777689]Hello I had a problem about using mathematical formulas. someone showed this this site : [url]http://software-dev.jimdo.com/[/url] I found there the application, but I don't know how to get the unit. did someone already use it?[/QUOTE] Before you go ahead and purchase something, did you check out an open source option: … | |
Re: You have 2 syntax problems and one logic problem. The syntax problems are: [list=1] [*]You don't need a semi-colon at the end of a line that contains a control structure, like an [icode]if[/icode] statement. That is, this is incorrect: [code] if ( someCondition ); /* Do things */ [/code] You … | |
Re: I would try and have a play with the list of global constants that you have at the top of salary.h. It looks like some of them could be incorporated into the [icode]Salary[/icode] class itself. Specifically, [icode]MINRAISE[/icode], [ICODE]MINSALARY[/ICODE], [ICODE]MIDRAISE[/ICODE], [ICODE]MAXRAISE[/ICODE] and [ICODE]MAXSALARY[/ICODE]. You could make them [icode]static const[/icode] members of … | |
Re: how are you trying to use [icode]Salary::operator>>[/icode]? What exactly is the error? You have declared [icode]operator>>[/icode] as [icode]private[/icode], so you can't call it from outside the class. That might be part of the problem... | |
Re: You're probably going to need to do better than that to get a reasonable response. What is the code supposed to do? What is the actual problem? Are there compilation errors, does it crash with some error? Also, use code tags to make your code readable. | |
Re: [QUOTE=jonnyboy12;1774542]Hello all. I am trying to convert a c document to c++. I requires that i use the out word like this. [CODE] if (executeCommand("QUIT", out response)) [/CODE] is there and out for c, or a better way that i'm unaware of. Thanks all for your time. bye[/QUOTE] Isn't [icode]out[/icode] … | |
Re: You can get input from the user using [icode]operator>>[/icode]: [code] #include <iostream> #include <string> int main() { std::string name1, name2, city; std::cout << "Enter names and city:" << std::endl; std::cin >> name1 >> name2 >> city; std::cout << "Hello, " << name1 << " " << name2 << " from … | |
Re: If you look at the documentation for [icode]QString[/icode] [URL="http://qt-project.org/doc/qt-4.8/qstring.html#at"]here[/URL] you can see that [icode]QString::at[/icode] is declared as: [code] const QChar QString::at ( int position ) const [/code] As you can see, the [icode]at[/icode] member returns a [icode]QChar[/icode] by [i]value[/i], which means you can use this method to see the value … | |
Re: I'm not sure that what you have implemented is a [i]sparse[/i] array. I think that the usual way to make a sparse array or matrix is to store the data in an [i]indexed form[/i]. The idea is that if you have an array that is 10000 elements in size, but … | |
Re: [QUOTE=phorce;1772204]Have you heard of an FFT (Fast Fourier transform) it's this way I'm trying to implement.[/QUOTE] I'm afraid I don't see how any of this relates to FFTs? Are you trying to implement some kind of bit reversal? [QUOTE=phorce;1772204]If I have: Matrix 1: 0 1 1 1 1 0 1 … | |
Re: You can check for allowed types at compile time using something like this: [code] template< typename T > struct type_validator; template<> struct type_validator< int > {}; template< typename T > T f( const T& x ) { type_validator< T >(); return x; } int main() { int a = 2; … | |
Re: The error that you mention occurs if you don't include [icode]QtGui[/icode] when compiling. If you are using qmake then you might have a line like [icode]QT = core[/icode] In your [icode].pro[/icode] file, if you change it to: [icode]QT = core gui[/icode] Then the compiler should be able to find the … | |
Re: I think that line 29 should be [icode]strcpy(PersonPointer[i].name, temp);[/icode] Instead of [icode]strcpy(PersonPointer.name, temp);[/icode] | |
Re: Could [URL="http://www.boost.org/doc/libs/1_49_0/doc/html/any.html"]boost::any[/URL] help? |
The End.