Arrays of Structs
main.cpp
1234567891011121314151617181920#include <iostream> #include <string> struct Person { std::string name; int age; double height; }; int main() { Person people[3] = { {"Alice", 30, 5.5}, {"Bob", 25, 5.9}, {"Charlie", 28, 5.7} }; for (int i = 0; i < 3; ++i) std::cout << "Name: " << people[i].name << std::endl; }
Note
Tout était clair ?
Merci pour vos commentaires !
Section 2. Chapitre 3
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Suggested prompts:
Can you show me how to declare an array of Person structs?
What is the syntax for creating a vector of Person structs?
Can you give an example of adding a new Person to a vector?
Génial!
Completion taux amélioré à 8.33
Arrays of Structs
Glissez pour afficher le menu
main.cpp
1234567891011121314151617181920#include <iostream> #include <string> struct Person { std::string name; int age; double height; }; int main() { Person people[3] = { {"Alice", 30, 5.5}, {"Bob", 25, 5.9}, {"Charlie", 28, 5.7} }; for (int i = 0; i < 3; ++i) std::cout << "Name: " << people[i].name << std::endl; }
Note
Tout était clair ?
Merci pour vos commentaires !
Section 2. Chapitre 3