Похожие чаты

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 ответов

11 просмотров

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.

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

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

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
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
есть ПО, которое лежит папкой, по сути и не инсталится, а просто запускается. Надо раскидать по машинам в домене. Я так понял, что прям настройками GPO, копировать я смогу тол...
Dmitriy
8
any reference of this implementation?
BitBuddha
29
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
16
Добрый день! Скажите пожалуйста, а какие программы вы бы рекомендовали написать для того, чтобы научиться управлять памятью? Можно написать динамический массив, можно связный ...
Филипп
7
Also, why can’t the community have a vote/ say when it comes to initiatives like buybacks. Isn’t the point of crypto decentralisation? Don’t we deserve input as long term supp...
👨🏽‍🦰
13
Карта сайта