C++ Cpp Console Renaming

  • Автор темы Автор темы Phillip
  • Дата начала Дата начала
Начинающий
Начинающий
Статус
Оффлайн
Регистрация
17 Сен 2023
Сообщения
6
Реакции
4
C++:
Expand Collapse Copy
#include <windows.h>
#include <thread>
#include <chrono>
#include <cstdlib>
#include <ctime>

void update() {
    const int stringL = 20;

    std::srand(static_cast<unsigned int>(std::time(nullptr)));

    wchar_t module[MAX_PATH];
    GetModuleFileName(nullptr, module, MAX_PATH);
    std::wstring ofn = module;

    while (true) {
        std::wstring rstring;
        const wchar_t Char[] = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        const int CLen = sizeof(Char) / sizeof(Char[0]) - 1;
        for (int i = 0; i < stringL; ++i) {
            rstring += Char[rand() % CLen];
        }

        size_t lsp = ofn.find_last_of(L"\\");
        std::wstring nfn = ofn.substr(0, lsp + 1) + rstring + L".exe";

        SetConsoleTitle(rstring.c_str());
        MoveFile(ofn.c_str(), nfn.c_str());

        std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay
    }
}
int main() {
    std::thread titleThread(update);

    titleThread.join();
    return 0;
}


 
Ну и нахуя? Это сделает любой человек который сидит в плюсах больше 0.000001 секунды
/del бесполезно
 
Ну и нахуя? Это сделает любой человек который сидит в плюсах больше 0.000001 секунды
/del бесполезно


я сделал это ради забавы и опубликовал это потому что подумал что некоторым людям это может принести пользу а не потому что это сложно
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Учим язык.День первый.
 
better use std::mt19937

can be declared as constexpr

huge naming problems, some variable names look unclear as well

C++:
Expand Collapse Copy
int main() {
    std::thread titleThread(update);

    titleThread.join();
    return 0;
}
could be
C++:
Expand Collapse Copy
int main() {
    std::thread(update).join();

    return 0;
}
 
better use std::mt19937


can be declared as constexpr

huge naming problems, some variable names look unclear as well


could be
C++:
Expand Collapse Copy
int main() {
    std::thread(update).join();

    return 0;
}

i had it in my code before in a actual console program when i was updating it after the program ran to not cause lag lmao
 
also the windows.h include is a huge red fuckin flag, define WIN32_LEAN_AND_MEAN at the very least
 
with best yougame practics (without jthread, only C++11 code :D)
C++:
Expand Collapse Copy
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <thread>
#include <chrono>
#include <random>

static std::wstring generateRandomString(int length) {
    const wchar_t Char[] = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    const int CLen = sizeof(Char) / sizeof(Char[0]) - 1;

    std::wstring rstring;
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dis(0, CLen - 1);

    for (int i = 0; i < length; ++i) {
        rstring += Char[dis(gen)];
    }

    return rstring;
}

static void update() {
    constexpr int stringL = 20;
    while (true) {
        SetConsoleTitle(generateRandomString(stringL).c_str());
        std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay
    }
}

int main() {
    std::thread(update).join();
    return 0;
}
 
with best yougame practics (without jthread, only C++11 code :D)
C++:
Expand Collapse Copy
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <thread>
#include <chrono>
#include <random>

static std::wstring generateRandomString(int length) {
    const wchar_t Char[] L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
can't you construct this using a for loop and an 'a' char?
 
with best yougame practics (without jthread, only C++11 code :D)
C++:
Expand Collapse Copy
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <thread>
#include <chrono>
#include <random>

static std::wstring generateRandomString(int length) {
    const wchar_t Char[] = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    const int CLen = sizeof(Char) / sizeof(Char[0]) - 1;

    std::wstring rstring;
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dis(0, CLen - 1);

    for (int i = 0; i < length; ++i) {
        rstring += Char[dis(gen)];
    }

    return rstring;
}

static void update() {
    constexpr int stringL = 20;
    while (true) {
        SetConsoleTitle(generateRandomString(stringL).c_str());
        std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay
    }
}

int main() {
    std::thread(update).join();
    return 0;
}
Код:
Expand Collapse Copy
#include <iostream>
#include <thread>
#include <chrono>
#include <random>

constexpr int STRING_LENGTH = 20;
constexpr int DELAY_MS = 200;

std::wstring generateRandomString(int length) {
    const wchar_t CHARACTERS[] = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    const int CHARACTERS_COUNT = sizeof(CHARACTERS) / sizeof(CHARACTERS[0]) - 1;

    std::wstring result;
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dis(0, CHARACTERS_COUNT - 1);

    for (int i = 0; i < length; ++i) {
        result += CHARACTERS[dis(gen)];
    }

    return result;
}

void updateTitle() {
    while (true) {
        SetConsoleTitle(generateRandomString(STRING_LENGTH).c_str());
        std::this_thread::sleep_for(std::chrono::milliseconds(DELAY_MS));
    }
}

int main() {
    std::cout << "Чтобы выйти, нажмите Ctrl+C." << std::endl;

    std::thread(updateTitle).join();

    return 0;
}
clеan
 
Код:
Expand Collapse Copy
#include <iostream>
#include <thread>
#include <chrono>
#include <random>

constexpr int STRING_LENGTH = 20;
constexpr int DELAY_MS = 200;

std::wstring generateRandomString(int length) {
    const wchar_t CHARACTERS[] = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    const int CHARACTERS_COUNT = sizeof(CHARACTERS) / sizeof(CHARACTERS[0]) - 1;

    std::wstring result;
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dis(0, CHARACTERS_COUNT - 1);

    for (int i = 0; i < length; ++i) {
        result += CHARACTERS[dis(gen)];
    }

    return result;
}

void updateTitle() {
    while (true) {
        SetConsoleTitle(generateRandomString(STRING_LENGTH).c_str());
        std::this_thread::sleep_for(std::chrono::milliseconds(DELAY_MS));
    }
}

int main() {
    std::cout << "Чтобы выйти, нажмите Ctrl+C." << std::endl;

    std::thread(updateTitle).join();

    return 0;
}
clеan
SetConsoleTitle don't include, have a nice day :roflanEbalo: change pls SetConsoleTitle(generateRandomString(STRING_LENGTH).c_str()); to std::cout << "\033]0;" << generateRandomString(STRING_LENGTH) << "\007";, thx
 
using 'a' to populate the char array, because 'a'+1 is 'b', etc.

assuming en_US.UTF-8
C++:
Expand Collapse Copy
#include <iostream>
#include <thread>
#include <chrono>
#include <random>

constexpr int STRING_LENGTH = 20;
constexpr int DELAY_MS = 200;

static std::string generateRandomString(int length) {
    constexpr char startChar = 'a';
    constexpr int CLen = 26; // Number of characters in the English alphabet

    std::string rstring;
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dis(0, CLen - 1);

    for (int i = 0; i < length; ++i) {
        rstring += startChar + dis(gen);
    }

    return rstring;
}

static void updateTitle() {
    while (true) {
        std::cout << "\033]0;" << generateRandomString(STRING_LENGTH) << "\007";
        std::this_thread::sleep_for(std::chrono::milliseconds(DELAY_MS));
    }
}

int main() {
    std::cout << "Press Ctrl+C to exit." << std::endl;

    std::thread(updateTitle).join();

    return 0;
}
Good luck :)
 
no way bro thanks for that super code now my cheat is ud on every ac :hearteyecat::hearteyecat::hearteyecat:☝☝
totally agree, that's all bullshit, rather use your ud bypass:
Пожалуйста, авторизуйтесь для просмотра ссылки.

1705800638815.png

upd: bloody hell... powered by chatgpt ?
 
Назад
Сверху Снизу