170 похожих чатов

Как вывести Hello world на с++?

13 ответов

8 просмотров

Хз

#include <iostream> #include <algorithm> template <typename ... _Args> class hello_world_printer{private: template<typename _Sequence_Argument> constexpr auto push_one(_Sequence_Argument&& arg){ if constexpr(!std::is_integral_v<std::decay_t<_Sequence_Argument»){ return int(arg); } else{ return char(arg); }} std::array<char, sizeof...(_Args)> arguments; public: constexpr hello_world_printer(_Args... args) : arguments({push_one(args)...}){} constexpr auto get() const noexcept{ return arguments;} template<typename _Ch, typename _Tr, typename _Tuple, std::size_t ... _Is> static constexpr void print_impl( std::basic_ostream<_Ch, _Tr>& ostream, const _Tuple& t, std::index_sequence<_Is...>){ ((ostream « (_Is == 0 ? "" : ", ") « std::get<_Is>(t.get())), ...); }}; template <typename _Ch, typename _Tr, typename ... _Args> constexpr std::ostream& operator « ( std::basic_ostream<_Ch, _Tr>& ostream, const hello_world_printer<_Args...>& printer){ ostream « '('; hello_world_printer<_Args...>::print_impl(ostream, printer, std::index_sequence_for<_Args...>());return ostream « ')';} int main(){ std::cout « hello_world_printer('H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd') « std::endl; return EXIT_SUCCESS;}

Vitalii
Какой стандарт?

Да любой по идее. От 11

floy.- Автор вопроса
Dian Blasphemous¿
#include <iostream> #include <algorithm> template...

вроде ругается, где-то ошибка... ``` main.cpp:24:15: error: storage class specified for a member declaration constexpr auto get() const noexcept { return arguments; } ^ main.cpp:24:31: error: expected ';' at end of declaration list constexpr auto get() const noexcept { return arguments; } ^ ; main.cpp:26:135: error: unexpected character <U+00AB> static constexpr void print_impl(std::basic_ostream<_Ch, _Tr> &ostream, const _Tuple &t, std::index_sequence<_Is...>) { ((ostream « (_Is == 0 ? "" : ", ") « std::get<_Is>(t.get())), ...); } ^~ main.cpp:26:161: error: unexpected character <U+00AB> static constexpr void print_impl(std::basic_ostream<_Ch, _Tr> &ostream, const _Tuple &t, std::index_sequence<_Is...>) { ((ostream « (_Is == 0 ? "" : ", ") « std::get<_Is>(t.get())), ...); } ^~ main.cpp:11:12: error: expected '(' after 'if' if constexpr (!std::is_integral_v < std::decay_t < _Sequence_Argument») ^ main.cpp:28:47: warning: variadic templates are a C++11 extension [-Wc++11-extensions] template <typename _Ch, typename _Tr, typename... _Args> ^ main.cpp:29:1: error: unknown type name 'constexpr' constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ main.cpp:29:16: warning: variable templates are a C++14 extension [-Wc++14-extensions] constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ main.cpp:29:23: error: expected ';' at end of declaration constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ ; main.cpp:29:57: error: use of undeclared identifier '_Ch' constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ main.cpp:29:103: error: use of undeclared identifier '_Args' constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ main.cpp:29:25: error: C++ requires a type specifier for all declarations constexpr std::ostream &operator << (std::basic_ostream<_Ch, _Tr> &ostream, const hello_world_printer<_Args...> &printer) ^ main.cpp:32:25: error: use of undeclared identifier '_Args' hello_world_printer<_Args...>::print_impl(ostream, printer, std::index_sequence_for<_Args...>()); ^ main.cpp:32:70: error: no member named 'index_sequence_for' in namespace 'std' hello_world_printer<_Args...>::print_impl(ostream, printer, std::index_sequence_for<_Args...>()); ~~~~~^ main.cpp:32:89: error: use of undeclared identifier '_Args' hello_world_printer<_Args...>::print_impl(ostream, printer, std::index_sequence_for<_Args...>()); ^ fatal error: too many errors emitted, stopping now [-ferror-limit=] 4 warnings and 20 errors generated. ```

Dian Blasphemous¿
#include <iostream> #include <algorithm> template...

Значит так милок. Вы забыли включить array.

floy.
вроде ругается, где-то ошибка... ``` main.cpp:24:...

Замени все » на >> Код был скопирован из вк, а он заменяет >> и <<

Vitalii
Значит так милок. Вы забыли включить array.

Т.е. то, что код написан в 1 строку кода и он буквально выводит хелло ворлд через миллион абстракций, тебя вообще не смущает?)

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

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

Anyone here suffers from unexplained aural migraines, who would be up for talking for a bit? Doesn't *have* to be aural, but I am not asking about headaches, I mean actual mi...
Martin Rys
55
подскажите пожалуйста, как мне освободить результат записанный в переменную result? в чем проблема подскажите если МОЖЕТЕ?
Михаил Helper
28
есть тут кто-то , кто только начал изучать си? если проходите курс на степике или как-то сами изучаете, пишите, может, скооперируемся?..
Eule
25
Слушайте, ещё такая интересная задачка. Сделан аудит действий пользователей через триггеры в базе, соответственно каждый пользователь имеет свой логин и пароль в базе. Это пре...
Сергей Бычков
12
Скажите, тут нет проблемы? IMyInterface1 = interface function GetInterface2: IInterface2; ... function TMyInterface.GetInterface2: IInterface2; begin Result := TI...
Ruslan aka DUDE
18
вопрос по москвину - не понимаю вот такого вопроса похоже Сколько разных всегда завершающихся функций с типом a -> a -> b -> a -> a можно реализовать? Две функции одинаково...
Fedor
11
Кстати, раз про скачивание файлов разговор зашел) Сделал бота для себя (транскрибирующего и суммаризирующего встречи) но не ожидал что за 2 месяца 10к пользователей набежит😅...
Andrey Obolenskiy
8
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
Утра доброго. Просветите пожалуйста. Хочу сделать rest сервер на делфи. Посмотрел 3 фреймворка: dmvc, Mars, mormot. Ни в одном из них не упоминается ассинхронная обработка вхо...
Сергей Бычков
10
Как попросить stack install делать executable без .exe на винде?
Danila Danko
9
Карта сайта