202 Posted Topics
Re: As others have said - there is no change in syntax when using an API. You need to learn about C++ before you learn how to perform specific output with it (ie, a GUI). However, its very difficult to learn C++ when you have no means of outputting data. That's … | |
Re: #2: if you don't know how to do that, use [URL="http://www.cplusplus.com/reference/iostream/ifstream/"]ifstream[/URL] to read from files and [URL="http://www.cplusplus.com/reference/iostream/ofstream/"]ofstream[/URL] to write to them (or just [URL="http://www.cplusplus.com/reference/iostream/fstream/"]fstream[/URL] for both). Quick example: [CODE] #include <fstream> using namespace std; int main() { int data = 5; ofstream fout("myfile.txt"); fout << data; fout.close(); int moreData; ifstream … | |
Re: @OP Post some code. And use [noparse][code][/code][/noparse] tags when you do so. | |
Re: I used to use GameMaker. There used to be tutorials on the site, but GameMaker got bought by YoYo games, so I'm not sure if they're anywhere anymore. Ill see if I have any saved on my computer somewhere if I have the time. A nice thing about GMaker is … | |
Re: That's more of a math question than a C++ question. At any rate, I believe it has something to do with the Pythagorean theorem. The 2D distance formula is sqrt((x2-x1)^2 + (y2-y1)^2) = D. I'm unsure what the 3D equation is. | |
Re: I don't really think it would make sense to learn one without sort of learning the other. I mean they're mostly the same. When you begin to learn either language, you're going to cover basic flow control - if statements, loops, functions, etc. It's only when you get to classes … | |
Re: Just because IBM says something is wrong doesn't mean VC++ agrees. Heck, VC++ could make [ICODE]billybob[/ICODE] a primitive data type and still call itself a C++ compiler (though few others would agree - and that's really what matters). Whatever is in the ISO standard for C++ is what is allowed. … | |
I'm writing a program for a contest (it's a demo, not the actual thing - so I'm not cheating by asking for help - and my question isn't directly related to the algorithm they want anyway). To submit a program, you send them the .cpp file, and they execute it … | |
Re: Post the header file and the .cpp file. There's no specific special thing you need to do to create a header file. What you said could be correct, but it's a bit vague. | |
Re: The address of a variable returned by the reference operator (&) is not an l-value, meaning you can't put it on the left side of an assignment operator. Besides, why would you want to? | |
Re: [URL="http://winprog.org/tutorial/"]link[/URL], if you're on windows | |
Re: Do you mean manually deleting data at an address you chose? Or are you just asking what delete does? [CODE] int* x;//declare a pointer to an it x = new int;//create an int somewhere in memory and store its address in x *x;//access the actual int stored at the location … | |
Re: One very evident difference between the two myNodes is that the second one will be deleted at the end of scope, while the pointer will continue to exist until you manually delete it. Well, that wasn't exactly true. The pointer myNode will be deleted at the end of scope, but … | |
Re: I think what he's referring to in #1 is a NULL pointer: [CODE] int* x = NULL; //or int* x = 0; [/CODE] I'm guessing this is what is meant by #3: [CODE] int x[10] = {0}; x[3] = 5; x[4] = 13; int* pInt = (&x[3])+1; [/CODE] *pInt would … | |
Re: >>numInstances[7] would be the number of times 7 showed up shouldn't numInstances[6] be the number of times 7 was rolled? Like n1337 said, you should do: [CODE] numInstances[sum-1]++; [/CODE] otherwise, you'd be wasting numInstances[0], and when you roll a 12, you'd have nowhere to put it (since the highest index … | |
Re: The only insert function of the vector template I found takes two parameters - one of type size_t, and the other of type Item_type. When you call it, you're only specifying the Item_type parameter. Also, I believe the entire purpose of the VectorOfNotebooks class is to not have to use … | |
Re: To my knowledge, both DirectX and OpenGL are written with C or C++. You could write an API like them yourself using C++. On Windows, you can use SetPixel() to set a pixel on a screen. I believe that's one of the most basic graphical functions you can use (in … | |
I'm having problems creating an array with a dynamic size using new. Here is the relevant code: [CODE] enum LandCondition { Bad, Good }; //... int IMG_WIDTH, IMG_HEIGHT; LandCondition* land; //... land = new LandCondition[IMG_WIDTH][IMG_HEIGHT];//causes errors [/CODE] The errors VC++ gives me are: error C2540: non-constant expression as array bound … | |
Re: I myself have run into problems with side by side configuration, and while I don't fully understand it, it is not an issue with Vista. I've run into the same problem when moving an app from one xp machine to another. | |
Re: You don't even need Direct3D - the Windows API has your back: [URL="http://msdn.microsoft.com/en-us/library/ms532304(VS.85).aspx"]link[/URL] | |
Re: It means that strncpy is old and/or something better is around to use instead of it. | |
To my understanding, certain classes, like ifstream, have a conversion to a primitive data type, like bool. In other words, you can do this: [CODE] if((fin >> x) && done == false) //... [/CODE] Now, does this simply work because ifstream has the && operator overloaded, or can objects of … | |
Re: The code in header files is executed in the order you #include them. So if the code file1.h needs to be executed before the code in file2.h (for some reason), then they must be #included in that order. | |
Re: [QUOTE=Motvel;657389]Thank you! But, tell me please, in the first method why the blank character (the space) is omited by default? Is there one error, or such work the method?[/QUOTE] The extraction operator >> skips over whitespace. To read a file character by character including whitespace, use the get() method. Though … | |
Re: Why DirectX instead of OpenGL? Personally I use DirectX, but even if you don't mind DirectX being closed-source and platform-specific, you may still choose to use OpenGL. | |
Re: [QUOTE=Salem;657073] > Develop a program in C++ Is that an [URL="http://web.comhem.se/hansdotter/romanes.html"]order?[/URL][/QUOTE] Are you not supposed to know Latin to find that funny? | |
Say I have a file file1.h: [CODE] namespace a { int Func() { return 5; } } [/CODE] and a file file2.h [CODE] #include "file1.h" namespace a { class Foo { Foo(); }; } [/CODE] and file2.cpp: [CODE] #include "file2.h" a::Foo::Foo() { Func();//<---- } [/CODE] Can Func() be referenced like … | |
Re: Have you compiled and run this? This: [CODE]avgNoOfGuesses=sum/noofgamesplayed;[/CODE] seems like it would generate an error, since noofgamesplayed is 0, and you're dividing by it. Besides, that statement and the one above it are unnecessary. Do you need to write the functions, or do you simply need to call them? Either … | |
Re: [QUOTE=robertmacedonia;656744]Man, I realise that you could solve the problem right away, I know you guys are experienced and these problems are too easy for you. I just wanted to help the dude like some of you guys helped me. And now that he's got the solution, he can look at … | |
Re: Depending on your needs, you may also consider [URL="http://www.cplusplus.com/reference/stl/list/"]lists[/URL] or [URL="http://www.cplusplus.com/reference/stl/deque/"]deques[/URL]. Here's a reference for all STL containers: [URL="http://www.cplusplus.com/reference/stl/"]link[/URL] | |
In regard to good style, is it better to use the NULL macro, or should you just use 0? And should you cast either one to the type of pointer you're using? i.e.: [CODE] int* pInt = (int*)0;//this, int* pInt2 = 0;//this, int* pInt3 = (int*)NULL;//this, int* pInt4 = NULL;//or … | |
A friend of mine recently asked me how one would convert a .bmp font to a .ttf. I said I was unsure, but it got me thinking to how I would code a program to do that. How would someone who wants to create a .bmp to .ttf converter go … | |
Re: [QUOTE=Wiki_Tiki;655585][CODE]cout << " \n"; char letter; cout << "Enter a letter to end the program:\n"; cin >> letter; cout << "Goodbye.\n"; return 0; }[/CODE] I know this probably isn't going to be much help to you, but it's way easier and simpler to, instead of having to type a random … | |
Re: You might want to also add a check in converter() (or somewhere else) to make sure that the number of deaths is not 0. | |
Re: C++ arrays are static in size, yes, but the Standard Template Library has containers that can do what you want. [URL="http://www.cplusplus.com/reference/stl/list/"]lists[/URL] sounds like they may fit your needs, but [URL="http://www.cplusplus.com/reference/stl/vector/"]vectors[/URL] or [URL="http://www.cplusplus.com/reference/stl/deque/"]deques[/URL] may also be of use. As far as this:[code]CStringArray MyArray[numData][/code] You need to use dynamic memory to allocate … | |
Re: don't use char arrays or char*. use std::strings. if your input is a string, you can just use the [] operator to access elements in it (it's been overloaded) [CODE] string str = "Hello"; if(str[1] == 'e') //this is true [/CODE] If you really want to know how to convert … | |
Re: Just so you know, the typedefs aren't necessary to do what you want... they just make it much easier. You had the right idea on your own. If this [ICODE]vector<string>[/ICODE] is a 1D vector, and this [ICODE]vector<vector<string>>[/ICODE] is a 2D vector, then following the pattern, you should've been able to … | |
Re: Salem meant you should wrap your code in code tags (the (code) button on the top, or just type `YOUR CODE HERE`, with four spaces before code). Do you want the for loop to be part of this conditional: else if ((peso > 30) && (peso < 1000) && (dia … | |
Re: When you run the program, and you want to guess that your favorite food is pizza, do actually type in "pizza", or do you input 10? | |
Re: How did you store the first object? Repeating that should do it.... | |
Re: [QUOTE=Salem;653469]C++ is a language, as defined by ISO. Visual C++ is an implementation (like Borland, GNU, Intel). Any modern 32-bit compiler will probably meet your needs for learning C++.[/QUOTE] Wait, so every compiler is considered to have it's own "implementation" of C++? So, is it possible to have a compiler … | |
Re: Google is very nice: [URL="http://msdn.microsoft.com/en-us/library/9yb20073(VS.71).aspx"]link[/URL] As others have said, post code, but this, or something like it, would cause the problem you're having: [CODE] void Func() { cout << "I am a function.\n"; } int main() { if(Func())//Func() returns nothing - you can't check if a nonexistent result is true … | |
Re: To address your first issue: void pointers. Google it. It's basically a pointer that has no type bound to it. I haven't used them too much but I think they fit your needs. Your second problem: You can check to see if there is data to be read. Use the … | |
Re: Post your errors, but at a glance: [CODE] void Mainmenu(); { string choice //missing semicolon //.... [/CODE] | |
Re: You need some [I]basic[/I] knowledge of the Windows API to use DirectX - so either way you should check this out: [URL="http://winprog.org/tutorial/simple_window.html"]http://winprog.org/tutorial/simple_window.html[/URL]. Buying books is a very good idea. I haven't read any books on the Windows API. A book on DirectX I did read was Beginning Game Programming, by … | |
Is it bad to make a reference parameter optional by giving it a default value? Like here: [CODE]int Parse(std::string filename, std::string& error = (std::string)"");[/CODE] Here, the caller of the function may pass an optional std::string that will be filled with an error message if there is one. Is this considered … | |
Re: [ICODE]exp *= exp[/ICODE] when exp is 1 means [ICODE]exp *= 1;[/ICODE], [ICODE]exp = exp*1;[/ICODE], [ICODE]exp = exp;[/ICODE]. That increment does nothing. To increase exp by 1 every iteration, do [ICODE]exp += 1;[/ICODE], if that's what you meant. Also, what is exponente? What is it set to? | |
Re: Is this what you mean? [CODE=C++] #include <iostream> using namespace std; class Foo { public: Foo() { cout << "Foo constructor\n"; } }; class SubFoo : public Foo { public: SubFoo() { cout << "SubFoo constructor\n"; } }; int main() { Foo* myfoo = new SubFoo(); return 0; } [/CODE] | |
Re: Why are you doing [ICODE]this->Close();[/ICODE]? You can just say [ICODE]Close();[/ICODE] if you're within the scope of the function, can't you? (unless you're trying to specify that you're not referring to some external Close() function, but I don't see how the compiler would think you mean that over a member of … |
The End.