S
S
sovux2020-08-19 15:50:19
C++ / C#
sovux, 2020-08-19 15:50:19

Reading from a file up to a certain point, how to implement it?

I have a txt file
with the following text:

1 0 Bur
1 1 Burn
1 2 Kanav
1 3 Mos
0 3 Strel

1 4 Gork
2 3 Chkal
3 3 Lenins
4 3 Zarec
5 3 DvR
6 3 Prol
7 3 Avtoz
8 3 Kom
8 4 Kirov
8 5 ParkK

and you need to read the coordinates separately and compare them with other coordinates in the program. and if they matched, display the text after the coordinates instead of the coordinates. for example, so that instead of 8.3 Kom
outputs here I want to embed it (this is only part of the code):
void tracePath(cell cellDetails[][COL], Pair dest)
{
    printf ("\n Marshrut: ");
    int row = dest.first;
    int col = dest.second;


    stack <Pair> Path;

    while (!(cellDetails[row][col].parent_i == row && cellDetails [row][col].parent_j == col))
    {
        Path.push(make_pair (row, col));
        int temp_row = cellDetails [row][col].parent_i;
        int temp_col = cellDetails [row][col].parent_j;
        row = temp_row;
        col = temp_col;
    }
   
    Path.push(make_pair(row,col));
    while (!Path.empty())
    {

        pair<int, int> p = Path.top();
        Path.pop();

//       
        if (p.first == 2 && p.second == 0)
        {
            printf("-> Burevestnik ");
        }
        else
        {
        printf("-> (%d,%d) ",p.first,p.second);
        }
    }
    return;

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Demidko, 2020-08-19
@Chronicler

That's the easiest way

std::string buf;
std::ifstream file("my.txt");
while(std::getline(file, buf)) {
   if(buf == "STOP") {
       break;
   }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question