I
I
Ivan Ershov2015-02-01 12:18:21
C++ / C#
Ivan Ershov, 2015-02-01 12:18:21

How to read (work with streams) only Russian words from a file?

For text parsing, I need to read only Russian words. How to "configure" a stream, for example, stringstream, so that, for example, it reads only Russian words or only English. .imbue is not working...

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
mamkaololosha, 2015-02-01
@mamkaololosha

stringstream is just a class that is described in the language specification with some functionality. If the developer of a certain compiler for some OS considers that it is necessary to add support for some non-ASCII language, then this will already be a crutch and non-cross-platform code. So you need to either look for such things under the platform, or hope that something like that is standardized in C11-14.

D
Don Kaban, 2015-02-01
@donkaban

No way. Come up with the predicate "this is a Russian word" and filter the stream.
The predicate itself - either "contains only Russian letters", or "is in the dictionary".

M
MiiNiPaa, 2015-02-04
@MiiNiPaa

What do you mean by "imbue is not working".
How do you read words?
If you use the >> operator, then in principle it is enough to change the ctype facet in the locale used to your own, where Latin letters will be considered whitespace characters (and you may have to force Russian letters to be understood as letters) and the usual extraction operator from the stream will read only sequences of Russian letters .
True, you need to be careful with encodings.
Program example:
ideone.com/Es7fs1
coliru.stacked-crooked.com/a/8c32c9870ca5aafc

V
Vladislav Shcherbakov, 2015-02-06
@vlad007700

www.cplusplus.com/reference/locale/isalpha

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question