presses a key on the keyboard ... Reveal Code
- for(int a=0;a<120;a++)
- {
- keybd_event(13,0,0,0);//down
- keybd_event(13,0,KEYEVENTF_KEYUP,0);//up
- Sleep(1000);
- }
Lazy loading in your app ... Reveal Code
- ---------------------------DLL
- extern "C" __declspec(dllexport) int *PushBack(int *x, int &N, int pb)
- {
- N++;
- pb=1;
- int *tmp=new int[N];
- for(int i=0; i
- #include
- #include
- using namespace std;
- typedef int*(*functionDll)( int *, int&, int );
- int main()
- {
- HMODULE hLib = LoadLibrary("DLL_Test.dll");
- if(hLib)
- {
- functionDll fpFunction = (functionDll)GetProcAddress(hLib,"PushBack");
- if(fpFunction)
- {
- cout << "Function load." << endl;
-
- srand ( time(NULL) );
- int N =rand() % 10 + 1; //радномим длинны массивов
- int *y;
- int *x=new int [N]; //выделяем память для матрицы х
- for(int i=0; i
-
C++: Random
Boost/std device random ... Reveal Code
- int GetRndNumber()
- {
- typedef boost::mt19937 RNGType;
- boost::random::random_device rd;
- RNGType rng(rd());
- boost::uniform_int<> one_to_one( 1, 10);
- boost::variate_generator< RNGType, boost::uniform_int<> >dice(rng, one_to_one);
- return dice();
- }
Get/Post Request POCO lib ... Reveal Code
- //----------GET
- string GetRequest(string reference)
- {
- try
- {
- string text;
- URI uri(reference);
- HTTPClientSession session(uri.getHost(), uri.getPort());
-
- string path(uri.getPathAndQuery());
- if (path.empty()) path = "/";
-
- HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
- req.set("User-Agent", "Poco");
- //session.setProxy("120.203.215.6", 85);
- session.sendRequest(req);
-
- HTTPResponse res;
- istream &is = session.receiveResponse(res);
- StreamCopier::copyToString(is, text);
- return text;
- }
- catch(...)
- {
- return "";
- }
- }
-
- void PostRequest(string reference, string id)
- {
- try
- {
- string text;
- URI uri(reference);
- HTTPClientSession session(uri.getHost(), uri.getPort());
- session.setKeepAlive(true);
- string path(uri.getPathAndQuery());
- if (path.empty()) path = "/";
-
- HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);
- req.setContentType("application/x-www-form-urlencoded");
- req.add("Accept", "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/ x-xbitmap, */*;q=0.1");
- req.add("Accept-Encoding","gzip,deflate");
- req.setKeepAlive(true);
- req.set("User-Agent", "Opera/9.80 (Windows NT 6.2; WOW64) Presto/2.12.388 Version/12.15");
- req.set("Cookie", "amcu_nn=1; advmaker_pop=1; PHPSESSID=6db1c4beb65ff4346c351459b1caf194");
- std::string reqBody("action=post&lnk="+id);
- req.setContentLength( reqBody.length() );
- session.sendRequest(req) << reqBody;
- }
- catch(...)
- {
- cout<<"fail";
- }
- }
C++: unique vector
removes duplicate elements ... Reveal Code
- #include
- #include
- #include
- using namespace std;
- template
- class myArray : public vector
- {
- public:
- void MyUniq();
- };
- template
- void myArray::MyUniq()
- {
- sort( this->begin(), this->end() );
- this->erase( unique( this->begin(), this->end() ), this->end() );
- unique (this->begin(), this->end());
- }
- int main()
- {
- myArray q;
- q.push_back(1);
- q.push_back(10);
- q.push_back(2);
- q.push_back(4);
- q.push_back(545);
- q.push_back(1);
- cout<<"do"<
-
takes a float number ... Reveal Code
- #include
- #include
- #include
-
- #include
-
- int main() {
- std::string str = "-3.14asd.asd.a0.23.asdfj234d.123.34++23.0";
- boost::regex rgx("\\-?\\d+\\.\\d+");
- std::copy(
- boost::sregex_token_iterator(str.begin(), str.end(), rgx),
- boost::sregex_token_iterator(),
- std::ostream_iterator (std::cout, " ")
- );
- getchar();
- }
C++: map of pointers to functions
map of pointers to functions ... Reveal Code
- #include
- #include
- #include
- using namespace std;
- void Func()
- {
- cout<<"pFunc()";
- }
- int main()
- {
- typedef void (*pFunc) ();
- vector> vec;
- vec.push_back(make_pair(true, &Func));
- vec.push_back(make_pair(false, &Func));
- for(auto it=vec.begin(); it!=vec.end(); ++it)
- {
- if(it->first) (it->second)();
- }
- getchar();
- return 0;
- }
C++: Private members
access to private members ... Reveal Code
- class Foo {
- private:
- char a;
- int b;
- float c;
-
- public:
- Foo() : a('a'), b(10), c(3.5f) {}
- };
-
- #include
- int main() {
- Foo* foo = new Foo();
- std::cout«"hello world " « *((float*) ((void*) foo)+2);
- delete foo;
- return 0;
- }
C++: XOR
XOR for each character in the string ... Reveal Code
- string XOR(string Text)
- {
- int i=0;
- while(Text[i])
- {
- char mask=(sin(3.14+i)*400)-(cos(3.14+i)*250/20);
- Text[i]=(Text[i]^mask);
- i++;
- }
- return Text;
- }
C++: Get Between the String
returns the string between two strings ... Reveal Code
- string GetBetween(string target, string left, string right)
- {
- size_t begin = target.find(left);
- size_t end = target.find(right);
- if(begin==string::npos || end==string::npos) return "";
- begin += left.size();
- return target.substr(begin, end - begin);
- }