Creating a bunch of objects in C++ -


i have quite simple situation don't know how resolve :
parsing file addresses (city, street , street number), , have following class :

class address {   std::string city;   std::string street;   std::string number; }; 

i create object each address find in file, can't know how many there since file can change. there way create array of objects ; or more suitable solution ?

note : parser works fine, there set values in objects.

you can use std::vector such purpose: http://en.cppreference.com/w/cpp/container/vector

#include <vector>  struct address {   std::string city;   std::string street;   std::string number; };  bool parseaddress(address& address) {     //todo: implement     //todo: return "true" if address has been parsed }  int main() {     std::vector<address> addresses;     address current;     while(parseaddress(current))     {         addresses.push_back(current);     }     return 0; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -