S
S
SodiTW2021-11-13 09:00:32
C++ / C#
SodiTW, 2021-11-13 09:00:32

How to read a line from a file before a line break or up to a certain character?

RAD Studio 10.4 development environment
The program reads data from an XML file, the file opens as follows

std::ifstream bfile;
bfile.open(w_file);
std::wbuffer_convert<std::codecvt_utf8_utf16<wchar_t>> conv(bfile.rbuf());
std::wistream in_file(&conv);

I also tried opening the file like this
std::wifstream in_file;
in_file.open(w_file);
in_file.imbue(locale(in_file.getloc(), new codecvt_utf8<wchar_t, 0x10ffff, consume_header>));

now the data is read like this
in_file>>line;
that is, according to the words, but some of the files contain a lot of data, because of which they can be read for too long.
Tried using
getlne(in_file, line);
but this sends the entire file to line.
When using
getline(in_file, line, '\n');
or
getline(in_file, line, '>');
gives the error "no matching function for call 'getline'.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question