466 Posted Topics

Member Avatar for chamnab

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 …

Member Avatar for Perry31
0
221
Member Avatar for Lucaci Andrew
Member Avatar for Lucaci Andrew
0
498
Member Avatar for missil9

Do you have to escape the angled brackets? So use `\<` and `\>` instead of `<` and `>`, respectively.

Member Avatar for missil9
0
317
Member Avatar for OrangeTree

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.

Member Avatar for OrangeTree
0
245
Member Avatar for abdelhakeem

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 …

Member Avatar for abdelhakeem
0
220
Member Avatar for lewashby

`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 …

Member Avatar for ravenous
0
153
Member Avatar for rezonk

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...

Member Avatar for abdelhakeem
0
222
Member Avatar for mrexp21
Member Avatar for subith86
0
145
Member Avatar for triumphost

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 :)

Member Avatar for ravenous
0
268
Member Avatar for jakezcop

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; }

Member Avatar for jakezcop
0
2K
Member Avatar for triumphost

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 …

Member Avatar for mike_2000_17
0
2K
Member Avatar for rahim_fayaz

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 …

Member Avatar for rahim_fayaz
0
141
Member Avatar for Despairy

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 …

Member Avatar for Despairy
0
296
Member Avatar for Miz_LiLO

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 …

Member Avatar for ravenous
0
120
Member Avatar for anonymous1987

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.

Member Avatar for ravenous
0
342
Member Avatar for ravenous

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 …

Member Avatar for santakdalai90
0
308
Member Avatar for smarty_t2

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..."?

Member Avatar for ravenous
0
2K
Member Avatar for BryantFury

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 …

Member Avatar for ravenous
0
567
Member Avatar for BryantFury
Member Avatar for khuzdaar

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 …

Member Avatar for rubberman
0
523
Member Avatar for SCass2010

`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 …

Member Avatar for ravenous
0
1K
Member Avatar for minghags

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; …

Member Avatar for minghags
0
261
Member Avatar for jiggaman77777

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 …

Member Avatar for ravenous
0
2K
Member Avatar for cplusfreak

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 …

Member Avatar for thines01
0
158
Member Avatar for swissknife007

There are techniques from bioinformatics to perform this kind of task. Try looking at [this](http://en.wikipedia.org/wiki/Sequence_alignment)

Member Avatar for ravenous
0
246
Member Avatar for fanii

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

Member Avatar for ravenous
-1
43
Member Avatar for mrcerimo

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 …

Member Avatar for mrcerimo
0
401
Member Avatar for tornado2232

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 …

Member Avatar for ravenous
0
191
Member Avatar for FaceSmasher

boost string algorithms can help you out here. As well as boost lexical_cast.

Member Avatar for ravenous
0
104
Member Avatar for 2hop260

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)

Member Avatar for 2hop260
0
757
Member Avatar for cahitburak

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 …

Member Avatar for cahitburak
0
967
Member Avatar for a_sd

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 …

Member Avatar for WaltP
0
139
Member Avatar for greatman05

[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 …

Member Avatar for ravenous
0
216
Member Avatar for triumphost

#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 :-)

Member Avatar for ravenous
0
94
Member Avatar for luislupe

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 …

Member Avatar for mike_2000_17
0
166
Member Avatar for bloominninja

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?

Member Avatar for bloominninja
0
238
Member Avatar for nunca

[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: …

Member Avatar for ravenous
0
104
Member Avatar for Mosey Mo

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 …

Member Avatar for ravenous
0
1K
Member Avatar for sfurlow72

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 …

Member Avatar for ravenous
0
314
Member Avatar for sfurlow72

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...

Member Avatar for sfurlow72
0
138
Member Avatar for rrrose16

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.

Member Avatar for ravenous
0
181
Member Avatar for jonnyboy12

[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] …

Member Avatar for ravenous
0
216
Member Avatar for coroche

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 …

Member Avatar for AdamLad3
0
104
Member Avatar for nine9hours

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 …

Member Avatar for nine9hours
0
211
Member Avatar for koricha

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 …

Member Avatar for koricha
0
152
Member Avatar for phorce

[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 …

Member Avatar for phorce
0
117
Member Avatar for triumphost

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; …

Member Avatar for mrnutty
0
4K
Member Avatar for nine9hours

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 …

Member Avatar for ravenous
0
256
Member Avatar for faraz ahmad

I think that line 29 should be [icode]strcpy(PersonPointer[i].name, temp);[/icode] Instead of [icode]strcpy(PersonPointer.name, temp);[/icode]

Member Avatar for ravenous
0
323
Member Avatar for maxmeier

Could [URL="http://www.boost.org/doc/libs/1_49_0/doc/html/any.html"]boost::any[/URL] help?

Member Avatar for maxmeier
0
147

The End.