This is my code.

#include "pch.h"
#include <iostream>
#include <Windows.h> 
#include <string>
#include <ctime>
#include <fstream>

using namespace std;

std::string AppName = "League of Legends";
LPCSTR LAppWindow = "Riot Client";
std::string AppStatus;

bool IsAppAvil;
bool Update;

int main()
{
    //Start App
    ShellExecuteA(NULL,"open","D:\\Games\\Riot Games\\League of Legends\\LeagueClient.exe\\",NULL,NULL, SW_SHOWDEFAULT);

    //Checking if app is running
    HWND hGameWindow = NULL;
    int timeSinceLAstUpdate = clock();
    int AppAvailTMR = clock();
    int onePressTMR = clock();
    int Timer = 0;
    DWORD dwProcID = NULL;
    HANDLE hProcHandle = NULL;

    while(!GetAsyncKeyState(VK_ESCAPE))
    {
        Timer += 1;
        if (clock() - AppAvailTMR > 100)
        {
            AppAvailTMR = clock();
            IsAppAvil = false;

            hGameWindow = FindWindowA(NULL, LAppWindow);

            if (hGameWindow)
            {
                GetWindowThreadProcessId(hGameWindow, &dwProcID);
                if (dwProcID != 0)
                {
                    hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
                    if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
                    {
                        AppStatus = "Faild to open.Invalid HANDLE";
                    }
                    else
                    {
                        AppStatus = "App opend";
                        IsAppAvil = true;
                    }
                }
                else
                {
                    AppStatus = "Faild to open.Didn't get the process ID";
                }
            }
            else
            {
                AppStatus = "Faild to open.App not found";
            }
        }

            Sleep(1000);
            system("cls");
            cout << "-------------------------------------------------------------------" << endl;
            cout << "                      Auto App Loger" << endl;
            cout << "-------------------------------------------------------------------" << endl;
            cout << "APP STATUS: " << AppStatus << endl;
            cout << "[ESC] exit" <<endl;

    }

    return ERROR_SUCCESS;
}

void ReadTxt() 
{
    std::string line_;
    ifstream file_("Nam.Password.txt");
    if (file_.is_open())
    {
        std::cout << "Reading file" << '\n' << endl;
        while (getline(file_, line_))
        {
            std::cout << line_ << '\n' << endl;
        }
    }
    else
    {
        std::cout << "File not found" << '\n' << endl;
    }
}

Dani AI

Generated

As pointed out, the file-reading routine is never executed; that is the primary reason the expected text never appears. A second, related problem is that the program repeatedly clears the console, which will remove any lines printed earlier unless the reader is called at the correct point in the flow.

A safe, simple fix is to invoke the reader from main in the place where its output should remain visible. Two common choices:

  • Call the reader once before the main loop when the file contents only need to be shown a single time.
  • Call the reader inside the loop but after the screen is cleared and before the status output so the file text appears along with the latest status.

Example (illustrative only — minimal call):

ReadTxt();   // call once, or place inside loop after clearing the screen

Short troubleshooting checklist to cover other causes:

  • Confirm the process actually reaches the reader: add short diagnostic prints before and after the call to detect control flow issues.
  • Verify the file path and working directory (an IDE may set a different working directory than the source file location); try an absolute path or print the current working directory to confirm.
  • Check that the file opens successfully (the reader already tests this, but add a distinct diagnostic message so it is obvious when the file is missing).
  • Avoid clearing the console immediately after printing the file; if a pause is needed, use a controlled pause or wait for a key so output can be observed.

Also note ’s earlier prompt for line numbers was useful — when diagnosing, point to where the reader should be invoked and whether the console-clearing code runs before or after that point.

Recommended Answers

All 3 Replies

That's nearly 100 lines of code, and I don't see "last" or "text" so you'll have to point out what text you are asking about along with the line number.

Line 87,90,95 text dosen't appear into my console.

Nowhere in the posted code do you call ReadTxt. That;s probably why it's never executed, which is why you don't see its output.

See how much better this site works when you give all the relevant info?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.