2,898 Posted Topics

Member Avatar for shahzaib g

If all you want is an easy solution, here is the easiest of all: [CODE] #include <cstdlib> int main() { system("octave"); return 0; }; [/CODE]

Member Avatar for NicAx64
0
86
Member Avatar for 344server

In this case, there are several options available to you. Here are two that I would recommend (btw, these are examples you can compile and run): 1) Polymorphism: This is a basic object-oriented implementation for this problem using an interface class for all class that could implement a response for …

Member Avatar for 344server
0
257
Member Avatar for fuggles

Again, polymorphism comes to the rescue. It is extremely typical, in fact I don't remember ever seeing any other solution to this, to use a "renderable" interface class and make all your objects that need to be rendered as derived from that interface: [CODE] //interface for all renderable objects class …

Member Avatar for mike_2000_17
0
100
Member Avatar for coolboss
Re: hii

indexing in C++ goes from 0 to N-1, so your code should be (in code tags) as: [CODE] #include<iostream> using namespace std; int main() //main always returns an int value. { int pro[100]; for(int a=99;a>=0;a--) { pro[a]=a+1; cout<<pro[a]<<"\t"; } return 0; } [/CODE]

Member Avatar for arkoenig
0
117
Member Avatar for srivardhanms

Ho, it took me a while to find this one.. here is your erroneous line 63: [CODE] char *buffer=new char(length+1); //these parenthesis should be square brackets. //like this: char *buffer=new char[length+1]; [/CODE] The effect of the normal parenthesis is to allocate space for only one character and initialize its value …

Member Avatar for mike_2000_17
0
2K
Member Avatar for newbie_to_cpp

I think it's a bit of a silly question. It is known that men and women have different and often complementary abilities (or at least inclinations for certain abilities). Since programming requires such a wide array of skills, I think you would probably find as good programmers in both genders, …

Member Avatar for NicAx64
0
110
Member Avatar for harris21

NO, at least, it would be extremely surprising and weird. Just try and see. I bet you that if you have a proper compiler, it will issue a compilation error. Why? Well it does not make any sense to have a pure virtual destructor. Because virtual destructors are not like …

Member Avatar for mrnutty
0
738
Member Avatar for Kanoisa

You guys have looked over the main point here. You cannot do a template specialization of a function for only a templated return type. That's why Kanoisa had to put a dummy parameter to the function, otherwise the compiler will not allow the specialization and say, in this case, "explicit …

Member Avatar for mike_2000_17
0
145
Member Avatar for Kakashi Hatake

The output of the first piece of code is 14 because the value of variable ival (referred to by ref) is set to the value of ival2 (which is 14). A reference can only be set once, upon construction (line 4). Afterwards, any operation on the reference is exactly as …

Member Avatar for Narue
0
1K
Member Avatar for Kakashi Hatake

I agree with sfuo, this is a matter of output formatting, not of the actual precision of the stored floating-point value. By default, the output format is somewhat automatic in the sense that if you have a number that is reasonably close to 0, it will be outputted in normal …

Member Avatar for mike_2000_17
0
104
Member Avatar for caut_baia

Try and check if the SetCommMask is return true or false. And use GetLastError to see the error message, that's all I can think of.

Member Avatar for mike_2000_17
0
125
Member Avatar for mike_2000_17

Hi experts! I have the following code which I use for dynamically creating objects in one module (executable or shared object (.so or .dll)) and be able to delete it from any other module while enforcing the call to the delete operator in the original module where the object was …

1
152
Member Avatar for Mozza314

The reason for this to happen is that the compiler generates a default = operator for any class that doesn't provide one. So, in this case, the compiler generates a = operator for A<double> = A<double> that has a better match than the A<double> = A<X>. So you would have …

Member Avatar for mike_2000_17
0
258
Member Avatar for harris21

If I may add a few things to the already good answers from Narue and Fbody. First, although Narue showed a case where explicitly calling a destructor, it's important to say that there is virtually no other reason where an explicit call to the destructor makes sense and the placement …

Member Avatar for mrnutty
0
300
Member Avatar for John Sand

I think the proper logic for the if-statements is this: [CODE] if(isalpha(textstring[i])) //if it is a letter (not a number or other crap) { letters_total++; //increment letter count. if(isupper(textstring[i])) //if upper-case, { textstring[i]=tolower(textstring[i]); //then make it lower case. } histogram_abs[(textstring[i] - 'a')]++; //at this point, only a lower-case letter could …

Member Avatar for John Sand
0
174
Member Avatar for Jackk123

As suggested by firsPerson, you need to add a seed for rand (srand) and closing the file is useless (it will be automatic when the program finishes and outfile is deleted). So, try this (and indent better in the future!): [CODE] #include "stdafx.h" #include <iostream> #include <fstream> #include <ctime> using …

Member Avatar for Jackk123
0
147
Member Avatar for Martje

From what you have posted, it doesn't really seem like you are really making what most people call a DataBase (which generally uses a database server using some SQL queries and such. Examples include MySQL, Oracle, etc.). In your case, this is what most programmers would call a memory serializer. …

Member Avatar for mike_2000_17
0
169
Member Avatar for group256

Well, you can use the std::sort algorithm in "#include <algorithm>". The only little problem is that it cannot be used with a list because [URL="http://www.cplusplus.com/reference/stl/list/"]list[/URL] provides only [URL="http://www.cplusplus.com/reference/std/iterator/BidirectionalIterator/"]bidirectional iterators[/URL], not [URL="http://www.cplusplus.com/reference/std/iterator/RandomAccessIterator/"]random access iterators[/URL], which is required for the [URL="http://www.cplusplus.com/reference/algorithm/sort/"]sort algorithm[/URL]. So you need to use a [URL="http://www.cplusplus.com/reference/stl/list/"]vector[/URL] instead. Also, the …

Member Avatar for mrnutty
0
5K
Member Avatar for Nathaniel10

In general it looks quite alright. Of course, I assume there will be future iterations on that problem in your book, because the instructions stated at the beginning will certainly be changed later to a more clever design. But I don't want to spoil it for you. One mistake that …

Member Avatar for Nathaniel10
0
91
Member Avatar for ganesh_IT

First of all, your file is in binary, because all data is binary on a computer. Second, you use the sizeof operator incorrectly. sizeof gives you the size of the type at compile-time. In this case the type of buf is a pointer to char which, most likely, has either …

Member Avatar for Fbody
0
145
Member Avatar for hardikp.001

Hardware programming on a PC is essentially I/O programming. This means you program drivers that communicate with hardware using some channel or port. So there is no general books about it. It's all about knowing the ports you work with, the OS calls necessary to open, configure and use the …

Member Avatar for mike_2000_17
0
349
Member Avatar for tehmarto

For starters, I don't know how to do what you want. But I do know that the code you have there is completely wrong because of the fact that the handle that is outputted by the LoadLibrary function is not by any means a pointer to the memory where the …

Member Avatar for tehmarto
0
133
Member Avatar for ticktock

Your problem is that you declare the array of vertices as having 9 coordinates in total, which would only include the first 3 points, i.e. the first triangle. [CODE]//This is where that is set: glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 9, &vertex[0], GL_STATIC_DRAW); //This is what it should be: glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 24, …

Member Avatar for ticktock
0
2K
Member Avatar for abysss

As Duki suggested, use the [URL="http://www.boost.org/doc/libs/1_44_0/doc/html/thread.html"]Boost Thread[/URL] library. You will have to install boost. This library in cross-platform and quite easy to use, and includes all the synchronization objects you can dream of. The C++0x standard will include a thread library, and that thread library will be directly taken from …

Member Avatar for abysss
0
145
Member Avatar for dorien

Well, okteta reads binary data and prints it out in hex format (to be more readable than if you opened a binary file in a text editor). So what you need to write is binary data: [CODE] ofstream myfile; myfile.open ("output.midi",ios::binary); char buffer[44] = {0x4D,0x54,0x68,0x64,0x00,0x00,0x00,0x06,0x00,0x01,0x00,0x01,0x00,0x80,0x4D,0x54,0x72,0x6B,0x00,0x00,0x00,0x16,0x80,0x00,0x90,0x3C,0x60,0x81,0x00,0x3E,0x60,0x81,0x00,0x40,0x60,0x81,0x00,0xB0,0x7B,0x00,0x00,0xFF,0x2F,0x00}; myfile.write(buffer,44); myfile.close(); [/CODE]

Member Avatar for dorien
0
9K
Member Avatar for 333kyle333
Member Avatar for raghamayee

I will advocate for Boost again... Boost has this Date-Time library which implements a microseconds clock (even a nanoseconds clock). It will run on any "normal" operating system. Of course, it will only really be as precise as your system can provide, but it will output the results in microseconds …

Member Avatar for mike_2000_17
0
144
Member Avatar for daviddoria

4) Use are reference of the Parent type to call the overload: [CODE] #include <iostream> class Parent { public: virtual int Add(int a, int b) = 0; int Add(int a) { return this->Add(a,a); } }; class Child1 : public Parent { public: int Add(int a, int b) { return a+b; …

Member Avatar for mike_2000_17
0
219
Member Avatar for pspwxp fan

This is because the function cin.get() will take a char* parameter and the size of the array of chars, and the compiler doesn't find the function that has only a char* parameter. You should change the "make" variable to type std::string (in #include <string>) and use getline() on the cin …

Member Avatar for embooglement
0
136
Member Avatar for EdAtTheAirport

szString1 is actually a pointer (or address) to the start of that chunk of memory with all the characters of the string (terminated by NULL or 0 or '\0', it's all the same). So when you pass szString1 as szTarget to the function, then szTarget also points to the start …

Member Avatar for arkoenig
0
201
Member Avatar for Duki

No no, no need for pointers here. the original solution posted is fine (without the const_cast non-sense). Just do this: [CODE] int& get_tp() { return tp; }; .. int Activate(int& tp, int weaponDamage, int attack ); [/CODE] That's totally fine, as long as it is acceptable in your design that …

Member Avatar for Duki
0
181
Member Avatar for mahsa.ehsani

Some compilers don't like it when the source file does not end with at least one empty line. See [URL="http://msdn.microsoft.com/en-us/library/4exw7xyc%28VS.71%29.aspx"]MSDN[/URL].

Member Avatar for NicAx64
-1
168
Member Avatar for NicAx64

Well, I just tested a similar code on my Linux machine (gcc 4.4, with only default options), and it's working properly. Maybe, just maybe, in your compiler / std-libraries, there is an additional [URL="http://www.cplusplus.com/reference/string/char_traits/"]char_traits template specialization[/URL] for a static array of chars. It would be very weird and non-standard, but …

Member Avatar for mike_2000_17
0
146
Member Avatar for willgr

In linux, the distributions (Ubuntu, Kubuntu, Fedora, Gnome, ..) and their families (Debian, ..) really mostly differ in where you find things in the computer (e.g. the different services and stuff your software links with). So that's why there are different "packages" for different distributions (usually by family). But really, …

Member Avatar for willgr
0
239
Member Avatar for gerard4143

@firstPerson: the point is not if the members make sense or not for the classes, it's about how to best implement the I/O for base and derived classes. @gerard: Here is what you should be doing, in my opinion (and this is what I actually do in my own code): …

Member Avatar for gerard4143
0
2K
Member Avatar for Bigbrain99

I don't know any good books from the beginning, but I'm sure you can't go wrong with Stroustrup, like ganesh suggests. I say, once you get through a C++ book that starts from the beginning and ends in somewhat advanced Object-Oriented Programming topics. Then you should definitely get project(s) going …

Member Avatar for Duki
0
155
Member Avatar for zhuimeng

Working with such a big array is going to be very slow and troublesome. Even if you make it work on your computer, will it work on another? I would suggest you think about the algorithm you have which uses this array and see if it is not possible to …

Member Avatar for zhuimeng
0
170
Member Avatar for woody1144

I'm guessing the [URL="http://www.cplusplus.com/reference/stl/bitset/to_ulong/"]to_ulong()[/URL] function is not good enough, i.e., you have too many bits in the bitset. If you can use it, then you can always memmove() the resulting unsigned long into an array: char[sizeof(unsigned long)]. If the bitset is bigger, consider splitting it up. Otherwise, I don't know, …

Member Avatar for woody1144
0
221
Member Avatar for kazkikay12

Please post the code between code tags, and indent it properly.. it's horrible to look at code that has no indentation: [CODE] #include <stdio.h> #include <conio.h> int main() { char charPtr[7]; int smallest, largest, middle, intNo; int dividend=0; int modolus=0; int valid; do { printf("Enter a seven digit number:\n"); scanf("%s", …

Member Avatar for kazkikay12
0
140
Member Avatar for sbrohee

There is _maybe_ a tricky way to do this. Since the == operator is not required to be inside the class definition of pair, you could implement it outside of it. Now the problem will arise with the two conflicting functions: the original (somewhere in the std namespace) and your …

Member Avatar for sbrohee
0
209
Member Avatar for billowillo

Did you make sure that SDL_LoadBitmap() has a valid output. In other words, those the bitmap load properly? Because the tutorial gives a Unix-style file path for the image, maybe it is wrong?

Member Avatar for billowillo
0
236
Member Avatar for chamika.deshan

The idea in your second solution is the right one, you want to copy the memory from the string that is passed to a newly allocated string. That's exactly correct and proper. The only problem you have is that you used sizeof() to get the length of the string. This …

Member Avatar for mike_2000_17
0
138
Member Avatar for VilePlecenta

First, is the external DLL file working? Second, maybe you should open the file with ios::binary flag as well. Maybe, I'm completely wrong though, I'm not expert on file systems. I can only suspect it is some sort of file header information Third, are those file sizes obtained from the …

Member Avatar for mike_2000_17
0
344
Member Avatar for John Sand

This loop is wrong: [CODE] while (!fin.eof()) { while (getline(fin, line)) { } } [/CODE] First, the outer condition is good, it means you want to read until the end of the file. The problem it that inside, you are reading all the lines in a loop and always overwriting …

Member Avatar for John Sand
0
187
Member Avatar for rishabbbh

goto is evil! You would do good to take it out of your programming vocabulary! Now, how on earth is this code supposed to jump to rec, sq, or cir? You never test the ch that is input. Since your choices are numbers, you should input a number, not a …

Member Avatar for mike_2000_17
0
145
Member Avatar for lil.jeantle

The other use of break is to "break" out of a loop. For example, the following three loops have essentially the same behavior (of course the first one is the simplest, best and most efficient): [CODE] const int N = 20; //upper-bound for(int i=0; i<N; ++i) { //.. do something …

Member Avatar for mike_2000_17
0
104
Member Avatar for carbonfinger

Maybe the precision is not good enough. Is it running in any sort of time that you know for sure is more than 1ms? If it does definitely take more than 1ms, then, as david said, try to inspect the tick count values directly to see if the GetTickCount() and …

Member Avatar for Kanoisa
0
137
Member Avatar for Nathaniel10

You have been looking at the wrong swap function. He means the swap function in the <algorithm> header. [URL="http://www.cplusplus.com/reference/algorithm/swap/"]see this page on it[/URL]. If you don't understand the template syntax, just assume it works for any type "T", and leave it at that for now. You would use it as, …

Member Avatar for Nathaniel10
0
194
Member Avatar for smcguffee

[URL="http://www.cprogramming.com/tutorial/initialization-lists-c++.html"]Here[/URL] is a good article on initialization lists. >>How much code can go in an initializer list? As much as you can while keeping the code neat. This means, don't go overboard trying to fit everything in the list, make sure it stays understandable and readable. Aside from that, there …

Member Avatar for StuXYZ
0
99
Member Avatar for jyotishkardey

[URL="http://en.wikipedia.org/wiki/Static_scoping#Dynamic_scoping"]Wikipedia[/URL] I never heard of dynamic scoping, and to no surprise after reading this wiki. There is no dynamic scoping in C++, and frankly, I'm happy there is none because it seems more hurtful than helpful.

Member Avatar for mike_2000_17
0
50

The End.