Is it possible to find the X and Y coordinates of a specific char from the console?

260 Views Asked by At

I'm printing a text file to the console with the following code:

bool Screen::GetLevelFile(string fileName, vector<string>& vecLevel)
{
    ifstream in(fileName.c_str());

    if (!in)
    {
        cerr << "Cannot open file: " + fileName << endl;
        return false;
    }

    string str;

    while (getline(in, str))
    {
        if (str.size() > 0)
        {
            vecLevel.push_back(str);
        }
        
    }
    in.close();


    return true;
}

Assume the textfile contains something like:

 #################################################   
 #  S                                            #   
 #                                               #   
 #                                               #   
 #                                               #   
 #                                               # 
 #                                               # 
 #                                               # 
 #                                               # 
 ################################################# 

Can I somehow find the x and y of 'S' in order to then replace it with '@' without using system("cls") and without editing the text file?

Edit: How I'm printing the file

void Screen::RenderScr()
{
    SetColor(FOREGROUND_RED | FOREGROUND_INTENSITY);

    string levelFile = "lvl1.txt";
    vector<string> levelVec;
    bool result = GetLevelFile(levelFile, levelVec);

    if (result)
    {
        //system("cls");
        cout << "\n\n" << endl;
        for (string &line : levelVec)
        {   
            cout << line << endl;
        }

    }
}
0

There are 0 best solutions below