title: How to make Account user generator c++ (problem: making array of objects and dynamically expanding it)
body: <p>I'm 15 and I moved to Sweden. I don't have time to study c++, because I need to learn the language, but later (few months probably), I'll continue with 300 page book (it's 500, but in 3 years I learned (through YouTube mostly) about 200 pages of that book). I'm not willing to learn right now about vector, so if you give me answer with vector, if you could explain to me how it works, or give me link where it "simply" explains vector.</p>
  
  <p>Anyway, being all said and done, here's my problem:
  I'm building in c++ program that on the start, it has 1 object(<code>NAobj</code>) where it will store your name and age, and then you can select option to continue to create another account, and so on. When you first run that program it makes <code>Aobj</code> array object and expands it every time when you want create new account. But I just can't get it to work.</p>
  
  <p>I found how I can expand array of objects, but, as I said, it's not realy working...</p>
  
  <p><a href="https://stackoverflow.com/questions/1350630/how-to-expand-an-array-dynamically-in-c-like-in-vector"><strong>How to expand an array dynamically in C++? {like in vector }</strong></a></p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;Windows.h&gt;
  
  using namespace std;
  int AccountFinder(string findName, string accountNames);
  
  
  
  class Account
  {
  public:
      Account()
      {
  
      }
  
      ~Account()
      {
  
      }
  
      string name = "-ERROR NAME-";
      int age = 18;
  
  
  private:
  
  };
  
  Account NAobj;
  int Asize = 1;
  
  string AName;
  string Iname;
  
  int ASelector;
  
  int main() {
      Account *Aobj = new Account[Asize];
      while (Iname.empty()) {
          cout &lt;&lt; "Name: #";
          getline(cin, Iname);
          if (Iname.empty())
          {
              cout &lt;&lt; '\a' &lt;&lt; endl;
              MessageBox(NULL, "No name found\nPlease enter name", "Error 01", MB_ICONERROR);
              system("cls");
          } 
          else if (Iname == " ") {
              cout &lt;&lt; '\a' &lt;&lt; endl;
              MessageBox(NULL, "Non suported name", "Error 02", MB_ICONERROR);
              system("cls");
              Iname.clear();
          }
          else {
              string a;
              cout &lt;&lt; "Crete account? y\\n #";
              getline(cin, a);
              if (a == "y") {
                  AName += Iname;
                  ////generatin account
                  NAobj.name = Iname;
                  Account *TAobj = new Account[Asize];
                  if (Asize == 1) {
                      copy(Aobj, Aobj + Asize - 1, TAobj);
                      delete[] Aobj;
                      Aobj = TAobj;
                      copy(Aobj, Aobj + Asize - 1, &amp;NAobj);
                  }
                  else {
                      copy(Aobj, Aobj + Asize - 1, TAobj);
                      copy(&amp;NAobj, &amp;NAobj, (TAobj + Asize - 1));
                      delete[] Aobj;
                      Aobj = TAobj;
                  }
  
                  ////
                  AName += " ";
                  cout &lt;&lt; "Want to continue? y\\n #";
                  getline(cin, a);
                  if (a == "y") {
                      system("cls");
                      Iname.clear();
                  }
                  else {
                      AName.resize(AName.size() - 1);
                  }
                  Asize++;
              }
              else {
                  cout &lt;&lt; "Want to continue? y\\n #";
                  getline(cin, a);
                  if (a == "y") {
                      system("cls");
                      Iname.clear();
                  }
                  else {
                      AName.resize(AName.size() - 1);
                  }
              }
          }
      }
      Iname.clear();
      cout &lt;&lt; "&gt;" &lt;&lt; AName &lt;&lt; "&lt;" &lt;&lt; endl;
      cout &lt;&lt; AName &lt;&lt; endl;
      string name;
      cin &gt;&gt; name;
      int ANumber = AccountFinder(name, AName);
      if(ANumber != -1)
          cout &lt;&lt; ANumber &lt;&lt; endl;
      else
          cout &lt;&lt; "no account name: &gt;" &lt;&lt; name &lt;&lt; "&lt; found" &lt;&lt; endl;*/
      cout &lt;&lt; endl;
      system("pause");
  }
  
  
  
  int AccountFinder(string findName, string accountNames) {
  
      string compareName;
      int Account = 0;
      bool space = TRUE;
      int startPos = 0;
      int a = 0;
  
      while (1) {
          while (1) {
              if (accountNames.at(a) == ' ') {
                  break;
              }
              else
                  a++;
              if (a == accountNames.size() - 1)
                  return -1;
          }
          compareName.resize(a - startPos);
          for (int b = startPos; b &lt; a; b++) {
              compareName.at(b - startPos) = accountNames.at(b);
          }
          if (findName == compareName) {
              return Account;
          }
          a++;
          startPos = a;
          if (Account &gt; 0) {
              1;
          }
          Account++;
      }
  }
  </code></pre>
  
  <p><code>Asize</code> - Account Size (indicate size of array)</p>
  
  <p><code>Aobj</code> - Account Object (array of account objects)</p>
  
  <p><code>NAobj</code> - New Account Object ("temporary" storage for account name, probably won't use that later...)</p>
  
  <p><a href="https://i.stack.imgur.com/DZoHn.png" rel="nofollow noreferrer">Program Output</a></p>
  
  <p>p.s.
  Sorry for my bad english and i know my program is a mess, but i'm lazy to tidy it up.</p>