Похожие чаты

That stateful behavior is caused by the fact that cin

and cout maintain synchronization with the C I/O functions, right? Or is it just their implementation? Because if it's the former, there is a solution.

1 ответов

13 просмотров

Interface is not implementation. Interface denotes what service a library provides, and implementation is how the service is performed internally. A stateless interface can have a stateful implementation. Consider a read-only caching database driver. A stateful interface can have a stateless implementation. Consider printf — the function alters the underlying IO state, while the implementation of printf itself is stateless [1]. Back to the problem, cin syncs with stdio by default, which means the *implementation* of cin is stateful. However, as an external user, you don't really care about the internal things [2]. What you actually care is the interface. cin introduces iostate, which effectively make the *interface* stateful. Now the state is exposed to external users, which means you have to think about the state between calls. To recapitulate, states are bad, but states are unavoidable when performing IO. As an I/O library author, you can add internal states to achieve syncing/caching or whatever. However, it's not wise to add states to your external interface to torture the library users. [1]: okay, I know that FILE has internal caching, but that's working at a lower layer. For the layer of formatting text, printf is stateless. [2]: unless you're not satisfied with the performance, see std::ios_base::sync_with_stdio.

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта