[QUOTE=jA_cOp;23408491]Take this example:
[cpp]
#include <iostream>
void setToOne(int& i)
{
i = 1;
}
int main()
{
int i = 0;
setToZero(i);
std::cout << i << std::endl;
}
[/cpp]
if anyone has any corrections or injections to make, please help me out :v:[/QUOTE]
setToZero(i)? Don't you mean setToOne? Silly billy :3:
[QUOTE=Chris220;23408554]setToZero(i)? Don't you mean setToOne? Silly billy :3:[/QUOTE]
I actually wrote it as setToZero first, but I figured it'd make more sense to reverse it :v:
Fixed that, thanks.
All right, thanks
btw this one was true
[QUOTE]The values of an enumeration type cannot be output directly to the standard output device.
A) True
B) False [/QUOTE]
[QUOTE=shemer77;23408693]All right, thanks
btw this one was true[/QUOTE]
It's a very poor question, because you can very much output enumeration values "directly" to the output pipe:
[cpp]
#include <iostream>
enum
{
ABC = 1;
};
int main()
{
std::cout << ABC << std::endl;
}
[/cpp]
However, as you'd probably expect, the output is '1'. I don't know what other result you'd be looking for when using enums, unless the book introduces them in a terribly poor way.
Never mind.
snip'd
How would I go about translating between two colors based on a lifetime variable.
In other words, I have a particle with a start color and an end color, the particle has a lifetime, I want the particle to go from the start color to the end color based on the life time.
I would do this.
Multiply color1 with life (life going from 1 to 0), multiply color2 with 1-life, add that together to get the final color.
If life is 1, the first color is multiplied by 1 and the second by 0, which only leaves he first color, if life is 0, the opposite thing happens.
I am having a problem, I am using a custom textbox to retrieve text using SFML and then trying to execute it using Lua, I need a platform portable way of converting a wstring to a char* for luaL_dostring
You using an sf::Unicode::Unicode::Text? Try casting to sf::Unicode::UTF8String and use the c_str function on that.
[QUOTE=ZeekyHBomb;23419755]You using an sf::Unicode::Unicode::Text? Try casting to sf::Unicode::UTF8String and use the c_str function on that.[/QUOTE]
Oh lol you're serious. I thought you made those names up as a joke.
It's better in SFML2.
I just started learning C++ and bought Accelerated C++ (as recommended by the sticky) and I need help configuring Microsoft Visual C++ 2010 Express. I wrote a small code:
[code]// a small C++ program
#include <iostream>
int main()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}[/code]
I'm not exactly sure what to do from here. I debugged it (F4) and then compiled it (F5) and nothing happened. I'm not sure if it's an inconsistency with the book or what. It appears this is in the Output under Debug.
[code]'getting_started.exe': Loaded 'C:\Users\Josh\Documents\Visual Studio 2010\Projects\getting_started\Debug\getting_started.exe', Symbols loaded.
'getting_started.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'getting_started.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'getting_started.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'getting_started.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'getting_started.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
The program '[5468] getting_started.exe: Native' has exited with code 0 (0x0).
[/code]
Any help would be appreciated, especially since I'm new.
The correct way to run a program like that is from the command line. Open a terminal and navigate to where getting_started.exe is located, then invoke it by typing its name:
[code]
C:
cd "C:\Users\Josh\Documents\Visual Studio 2010\Projects\getting_started\Debug\"
getting_started
[/code]
When you run it using the debugger, there won't be a terminal around to show you the output (although the IDE might help you around that), as it closes right away. You can see that it ran successfully by looking at the reported exit code: zero - by convention - means success, which is why you're returning 0 from main in your program.
Being the dummy I am, I don't exactly understand that, could you explain it a bit more? Sorry for my troubles.
[QUOTE=Zally13;23420912]Being the dummy I am, I don't exactly understand that, could you explain it a bit more? Sorry for my troubles.[/QUOTE]
Press super-key ("Windows key") + R to open Run prompt, enter "cmd". Now enter the three commands I posted above - you should see "Hello, world!" being output in the end.
C++ programs end when main finishes execution. The return value is a status code - whether the program ran successfully or not. Zero means success, hence "return 0;" means "finished successfully."
If you run a console application from the Windows shell (by double-clicking etc), the console will only be visible as long as the program is running. For your program, that means it ends immediately. Hence you should run it from the command line.
(Running it from the command line also lets you pass parameters to main, but you don't have to think about that yet)
That cleared it up. It worked successfully, thanks!
are you 64 bit or 86 bit
[editline]09:42PM[/editline]
are youn 64 bit or 86 bit??
64 bit.
[QUOTE=turb_;23421469]are you 64 bit or 86 bit
[editline]09:42PM[/editline]
are youn 64 bit or 86 bit??[/QUOTE]
:wtc:
Did turb_'s account get hijacked? Or is he just talking like that on purpose
[QUOTE=jA_cOp;23420992]Press super-key ("Windows key") + R to open Run prompt, enter "cmd". Now enter the three commands I posted above - you should see "Hello, world!" being output in the end.
C++ programs end when main finishes execution. The return value is a status code - whether the program ran successfully or not. Zero means success, hence "return 0;" means "finished successfully."
If you run a console application from the Windows shell (by double-clicking etc), the console will only be visible as long as the program is running. For your program, that means it ends immediately. Hence you should run it from the command line.
(Running it from the command line also lets you pass parameters to main, but you don't have to think about that yet)[/QUOTE]
Since he's using Microsoft Visual C++, he could also use Ctrl+F5. Or of course just pause the program with code with this right before the return.
[cpp]getchar();[/cpp]
[QUOTE=Chris220;23421815]:wtc:
Did turb_'s account get hijacked? Or is he just talking like that on purpose[/QUOTE]
He's drunk.
[QUOTE=Chris220;23421815]:wtc:
Did turb_'s account get hijacked? Or is he just talking like that on purpose[/QUOTE]
he's trying to act cool and is failing horribly.
I have a silly question, that's probably rather dumb and such. It's more about math then programming, but it does involve code. C++ code that is.
[code]
float dist_x = (x+15)-mouse_x;
float dist_y = (y+15)-mouse_y;
float dist_xy = sqrt(pow(dist_x,2)+pow(dist_y,2));
[/code]
Right now, I have this top-down walking guy that turns as you press left or right, then walks into the direction he is pointing. But I want him to always look at the location of the mouse, so that I can strafe and shoot where I look. The code above simply calculates all the distances on the X, Y and XY directions, so that I have all three sides of the imaginary triangle. Now I just need to calculate the angle, between 0 and 360 degrees, so that the player will look at the mouse. But whatever I try, it doesn't want to work.
I've tested the code above, and that gives out correct numbers.
That code returns me some odd number between 0.3 and 3.2.
Edit:
Now it's a number between 0 and 3.14.
might be in radians depending on what you're using
[QUOTE=SweetSwifter;23423803]That code returns me some odd number between 0.3 and 3.2.
Edit:
Now it's a number between 0 and 3.14.[/QUOTE]
And what does 3.14 look like? Pi.
Which tells you it's in radians
[editline]04:01PM[/editline]
:ninja:
You have to convert to degrees
Degrees = Radians * (180/PI)
Herpyderp, of course. Thanks, my brain decided not to work. :downs:
No problem :)
Wooh, it works now, my player looks at the mouse. But sadly, when I walk forward, it moves towards the mouse, then turns away in an elliptical path and walks the other way.
Sorry, you need to Log In to post a reply to this thread.