T
T
Trimsky2020-11-16 05:09:50
C++ / C#
Trimsky, 2020-11-16 05:09:50

Why does it return ELF?

Hello!
Please help
This code:

std::string youString(youTrue);
    std::ifstream ss(youString);;
    if(!ss.is_open()) {
        throw std::runtime_error("Такого файла не существует");
    }
    char buff[50];
 
    ss >> buff; // считали первое слово из файла
    std::cout << buff << std::endl; // напечатали это слово
    // Возвращает ELF
    ss.close(); // закрываем файл
    return "0";
}

When I enter test.txt as a test file (it contains the string "qwertyuiop"), I get not qwertyuiop, but "ELF".
Help me please!
The test.txt file is in the same directory.

UPD:
Question closed. It turns out I'm dumb and the first argument was a.out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maaGames, 2020-11-16
@Trimsky

Output a variable with the name of the file to the console. Because it feels like you specify the file through the command line argument, and then you open for reading not the file, but the executable file itself.
Well, it's better to open it in text form, and not in binary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question