Jump to content

Recommended Posts

Posted

post random snippets of c++

//i created a loop without knowing how to loop. without even knowing how to take input yet

#include <iostream>


unsigned int a = 1; //set a variable a nice value of some kind

void woo()//create a function to increment the variable
{
    a++;//increment the value
    std::cout << a;//print the variable to the screen
    woo();//call the function within itself
}//end the function definition

int main() {//begin the main function
    woo();//call the previously made function
    return 0;//end the main function
}//close the main function

//that is all

Posted

the best way to make an infinite loop is

for(;;)
{
     Sleep(10);
}

instead of something like

while(1 == 1)
{
     Sleep(10);
}
[code]

because when it all gets broken down into assembly instructions, the second loop boils down to a conditional jump (conditional meaning if a certain condition is true only then will it jump) as you can see this is not needed since its an infinite loop anyway the condition will never change so it will still always jump! so just use a for loop so it wont be checking that address unnecessarily every split second!

[code]
cmp [ADDRESS], 1
je loopstart

while the first is an UNconditional jump

jmp loopstart

although you may not notice much of a difference speed wise, use a for loop for infinite loops just to be getting top performance...

also the Sleep(10); is important in almost every infinite loop! So that your program never takes it up to 100% CPU usage! If you don't have any sleep in your loop you will notice lag! ;)

a random function that I like: atoi

converts an ascii string to and integer ascii to integer

char* stringnumber = "5000";

int numbernumber = atoi(stringnumber);

very helpful for reading numbers out of text files in string format, then converting them to actual binary so that you can use the number to do math!

http://www.cplusplus.com/reference/clibrar...tdlib/atoi.html

Posted

well my loop isn't exactly infinate. the process dies at a certain point.

my loop thing was made for 2 reasons.

1 im learning c++ and i wanted to see if a function could call itself since i cant call anything that was defined after it was called.

2. i wanted to push the cpu meter on vista to 100 percent on the laptop i was using so i just tried to write up a quick code in c++. i accomplished my goal halfway since it hovered around 50% but never hit 100% using just c++. though running 5 batch files that said

@echo off
:n
print 20004517239489824y3hf9gh3192854
goto :n

worked just fine.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...