Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to create array of structs in C++

1 Answer

0 votes
#include <iostream> 
  
struct Book { 
    std::string name;
    float price; 
}; 
    
int main() 
{ 
    Book arr[] = { { "c++", 37 }, 
                   { "java", 32 }, 
                   { "c", 41 }, 
                   { "python", 35 } }; 
  
    for (const auto &b : arr) {
        std::cout << b.name << " " << b.price << "\n";
    }
} 
  
  
  
/*
run:
  
c++ 37
java 32
c 41
python 35
  
*/

 





answered May 11, 2021 by avibootz
edited Feb 5, 2023 by avibootz

Related questions

3 answers 97 views
97 views asked May 11, 2021 by avibootz
2 answers 77 views
77 views asked Jan 21, 2022 by avibootz
1 answer 67 views
67 views asked May 11, 2021 by avibootz
1 answer 89 views
1 answer 19 views
...