[QUOTE=Meatpuppet;33801454]A quiz in my C++ book had a question that had me write a program that needed a password parsed via commandline. I tried using an if statement like "if(argv[1] = "r"). That didn't work. So I tried doing pointers and shit with it, by making a pointer point to a string where the string was "r". I tried using strcmp, but I couldn't get that to work either. It turns out that the answer was so fucking obvious, it was just "if(!strcmp(argv[1] = "r")". That's the only thing I didn't try. Fuck, I overcomplicate things way too much.[/QUOTE]
Use == to compare two variables. You're using =, which is the assignment operator.
[QUOTE=ief014;33801582]Use == to compare two variables. You're using =, which is the assignment operator.[/QUOTE]
Woops. I just typed the post wrong. And I'm pretty sure you can't compare char** and char.
[QUOTE=Meatpuppet;33801604]Woops. I just typed the post wrong. And I'm pretty sure you can't compare char** and char.[/QUOTE]
argv[1][0] == 'r'? Since it's just a single character you need to compare...
[QUOTE=raBBish;33802672]argv[1][0] == 'r'? Since it's just a single character you need to compare...[/QUOTE]
I was just using one character for testing purposes.
In XNA, my content folders for all my projects just became corrupted, and it does the same for each new project I create. What can I do to create new, non-corrupt ones?
Because the standard math library already contains a round function, which you're overloading. You need to rename yours.
[QUOTE=thomasfn;33812711]Because the standard math library already contains a round function, which you're overloading. You need to rename yours.[/QUOTE]God fucking damnit book. Tells me to name the damn function round.
[editline]20th December 2011[/editline]
Fuck I don't know how to use modf
[QUOTE=Meatpuppet;33812760]God fucking damnit book. Tells me to name the damn function round.
[editline]20th December 2011[/editline]
Fuck I don't know how to use modf[/QUOTE]
You know when everyone says don't using namespace std? This is why you don't using namespace std.
[QUOTE=Catdaemon;33812851]You know when everyone says don't using namespace std? This is why you don't using namespace std.[/QUOTE]
I haven't, because I'm just a beginner who's trying to get my way through this book so I can actually make something for once.
[editline]20th December 2011[/editline]
4. Create a void function called round() that rounds the value of its double argument to the nearest whole value. Have round() use a reference parameter and return the rounded result in this parameter. Demonstrate round() in a program. To solve this problem, you'll have to use modf() etc...
How can I input a reference parameter into modf, but modf only accepts non pointers in it's first parameter?
[editline]20th December 2011[/editline]
Nevermind I got it :)
[QUOTE=Meatpuppet;33812760]God fucking damnit book. Tells me to name the damn function round.
[editline]20th December 2011[/editline]
Fuck I don't know how to use modf[/QUOTE]
The author probably didn't know or care about the C++11 standard that was finalized about two months ago (which added std::round).
[QUOTE=Meatpuppet;33813286]Another question, probably due to the outdated-ness.
[cpp]void println(bool b, int indent = 0);[/cpp]
Why doesn't this work? I was taught that you can't have default arguments to the left of another argument that isn't a default.[/QUOTE]
It should work, unless you've put the default argument into both the method declaration and the method definition. It only needs to be in the prototype (declaration).
I'm trying to use the farseer physics engine with XNA, I've added the farseer XNA project to my current project and I've added the reference, but when I start typing "using Farseer" the reference doesn't appear... What am I missing ?
Is it normal to get a lot of warnings while building boost? I'm building it for vs2010 by the way.
It's normal to get a lot of warnings while building anything you haven't written yourself
[editline]20th December 2011[/editline]
If you write something by yourself there are usually more errors instead
Does anyone have some guidelines for in what order you should learn C++?
I know the basics, classes, strutcts, pointers, STL lists, vectors, queues, etc. But what next?
[QUOTE=Armandur;33816679]Does anyone have some guidelines for in what order you should learn C++?
I know the basics, classes, strutcts, pointers, STL lists, vectors, queues, etc. But what next?[/QUOTE]
Programming
[QUOTE=esalaka;33816841]Programming[/QUOTE]
I already do that.
[editline]20th December 2011[/editline]
Älä hävitä mustikoita metsässä
No specific order other than syntax and common coding guidelines followed by the standard library.
Having a rough digest of the standard library should be enough, since you can usually just take a look at the reference to see how exactly stuff works; you just need to know that it could be part of it.
[QUOTE=Armandur;33816957]I already do that.
[editline]20th December 2011[/editline]
Älä hävitä mustikoita metsässä[/QUOTE]
Älä puhu sekavia, ei tuo oo mikään sananlasku.
I mostly meant you should start writing little projects or programming experiments and learn stuff as you need it.
Posting here instead of Waywo because I'm retarded.
[quote]Terraria like setup, 2d, blokz an shit. The stuff here helped me create what so far seems to be working on the memory front, so now I need to ask one thing and confirm another.
Physics: I want to have circular objects, and other item physics in the game. Now, Box2D would work for this normally, but we're talking a world made up of voxel chunks that can change constantly.
The amount of memory and CPU time that would be wasted attempting to keep track of this entire (up to 10x10k for 100 million block) world as small Box2D cube shapes would be ridiculous.
On this note, if you have worked with Box2D more then I have (probably a certainty if you've really done much with it) might you have an idea how to fix this issue? The world will have other living NPCs and such in it so physics need to be all across the active world. Trailing worlds have more broad macro effects, so physics won't be active on them.
For the second quicker question, I have an array of chars acting as 8 bit flags for the voxels on the map. Would the easiest method to test if a flag is active a bitwise AND, with 8 corresponding chars with each having 1 bit active (ie. char x = 1, char y = 2, char z = 4, and so on).[/quote]
SUCCESS!
I've made a (kind-of) text based rpg engine where I can dynamically add Areas and connect them to other Areas which you can move around in, and now, [b]finally[/b], I got XML serialization working :)
Output:
[code]
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="9">
<Area class_id="0" tracking_level="1" version="0" object_id="_0">
<Blocked>0</Blocked>
<Hidden>0</Hidden>
<EnterText>Du befinner dig i klassrum 219</EnterText>
<DescriptionText>Undervisningssal</DescriptionText>
<Exits class_id="1" tracking_level="0" version="0">
<count>1</count>
<item_version>0</item_version>
<item class_id_reference="0" object_id="_1">
<Blocked>0</Blocked>
<Hidden>0</Hidden>
<EnterText>Du befinner dig pa plan 2</EnterText>
<DescriptionText>Undervisningssal</DescriptionText>
<Exits>
<count>2</count>
<item_version>0</item_version>
<item class_id_reference="0" object_id_reference="_0"></item>
<item class_id_reference="0" object_id="_2">
<Blocked>0</Blocked>
<Hidden>0</Hidden>
<EnterText>Du har trŴt in i Olles hǬe. SjŬv sitter han pƠen benheյg och jųer.</EnterText>
<DescriptionText>En hǬe i backen.</DescriptionText>
<Exits>
<count>2</count>
<item_version>0</item_version>
<item class_id_reference="0" object_id_reference="_1"></item>
<item class_id_reference="0" object_id="_3">
<Blocked>0</Blocked>
<Hidden>0</Hidden>
<EnterText>Du har lyckats kravla dig in i Heinrichs hǬe. Ljuset Ų skummt, men du kan se att han sitter dŲborte i sitt hղn och trycker.</EnterText>
<DescriptionText>En hǬe i backen, i Olles hǬe.</DescriptionText>
<Exits>
<count>1</count>
<item_version>0</item_version>
<item class_id_reference="0" object_id_reference="_2"></item>
</Exits>
</item>
</Exits>
</item>
</Exits>
</item>
</Exits>
</Area>
<Area class_id_reference="0" object_id_reference="_1"></Area>
<Area class_id_reference="0" object_id_reference="_2"></Area>
<Area class_id_reference="0" object_id_reference="_3"></Area>
</boost_serialization>
[/code]
[editline]20th December 2011[/editline]
Any ideas as to how I could accomplish outputting åäö to an xml archive using boost serialization? Or should I just use the corresponding escape sequences?
Just ignore my post then, it's okay :suicide:
I need some help with this, it appears I'm suffering from some form of a memory leak but I have no idea how to identify it. I've tried now 2 methods of fps counting and both claim my program to be suffering from it. Of course, it is as over the course of about 15 seconds it drops to 3-5 fps from 190-200 fps.
[code] public void init(){
try {
screen = new Screen(WIDTH, HEIGHT, new SpriteSheet(ImageIO.read(Game.class.getResourceAsStream("/icons.png"))));
} catch (IOException e) {
e.printStackTrace();
}
}
public void tick(){
screen.xScroll++;
screen.yScroll++;
tickCount++;
}
public void run(){
int frames = 0;
double secondsPerTick = 1 / 60.0;
double unprocessedSeconds = 0.0;
long previousTime = System.nanoTime();
int tickCount = 0;
boolean ticked=false;
init();
while(running){
long currentTime = System.nanoTime();
long passedTime = currentTime - previousTime;
previousTime = currentTime;
unprocessedSeconds += passedTime / 1000000000.0;
while(unprocessedSeconds > secondsPerTick){
tick();
unprocessedSeconds -= secondsPerTick;
ticked = true;
tickCount++;
if(tickCount % 60 == 0){
System.out.println(tickCount + " ticks, " + frames + " fps");
previousTime+= 1000;
tickCount = 0;
frames = 0;
}
}
if(ticked){
render();
frames++;
}
render();
frames++;
}
}
public void render(){
BufferStrategy bs = getBufferStrategy();
if(bs == null){
createBufferStrategy(3);
return;
}
screen.render(pixels, 0, WIDTH);
Graphics g = bs.getDrawGraphics();
g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
g.dispose();
bs.show();
}
[/code]
That's the code to what's creating and printing the fps and tickRate (tickrate is fixed at 60).
Any assistance would be well appreciated.
Try running it through a leak check tool.
[QUOTE=Octave;33822942]Try running it through a leak check tool.[/QUOTE]
Could you recommend one to me? I'm not familiar with any of them (due to never having this issue).
[QUOTE=WitheredGryphon;33822986]Could you recommend one to me? I'm not familiar with any of them (due to never having this issue).[/QUOTE]
I only have personal experience with valgrind which is Unix-like exclusive afaik, but if you're using Visual Studio there's a built in one: [url]http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=vs.80).aspx[/url]
[QUOTE=Octave;33823024]I only have personal experience with valgrind which is Unix-like exclusive afaik, but if you're using Visual Studio there's a built in one: [url]http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=vs.80).aspx[/url][/QUOTE]
I'm currently using Eclipse (java), and thanks, I'll look into it and update with further notice.
Once I'm done with this c++ book, where should I go? I want to learn how to create a simple 2d game, and I would like to learn how to do use utilizing my c++ knowledge. Any suggestions?
Sorry, you need to Log In to post a reply to this thread.