9.2.3 : Le main.cpp
Voici le main.cpp : On commence pas les includes standards :
1 2 3 |
#include <iostream> #include <ranges> #include <string_view> |
Ensuite, nous utilisons un namespace pour nous simplifier la vie :
1 |
using namespace std::literals; |
Notre fonction principale :
1 |
int main(){ |
Un exemple avec un certain nombre de répétitions :
1 2 3 4 5 |
// bounded overload for (auto s: std::views::repeat("C++"sv, 3)){ std::cout << s << ' '; } std::cout << '\n'; |
Un exemple avec autant de répétitions que l'on veut, qui est tout de même limité par take plus tard :
1 2 3 4 5 6 7 8 |
// unbounded overload for (auto s : std::views::repeat("I know that you know that"sv) | std::views::take(3)){ std::cout << s << ' '; } std::cout << "...\n"; return 0; } |
Le fichier main.cpp complet :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <iostream> #include <ranges> #include <string_view> using namespace std::literals; int main(){ // bounded overload for (auto s: std::views::repeat("C++"sv, 3)){ std::cout << s << ' '; } std::cout << '\n'; // unbounded overload for (auto s : std::views::repeat("I know that you know that"sv) | std::views::take(3)){ std::cout << s << ' '; } std::cout << "...\n"; return 0; } |
Le fichier main.cpp est disponible ici.