how to count an element within array

#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>


using namespace std;
struct book
{
string title;
string outhor;
int price;
};
int main()
{
string answer,str_counter,str_price;
int counter,book_counter;
book *books;
cout<<endl<<"how many books you want to add : ";getline(cin,str_counter);
stringstream(str_counter)>>counter;
books = new (nothrow) book[counter];
if(books == 0)
{
cout<<endl<<"sorry, not enought memmory to add a new book";
}
else
{
for(int i=0;i<counter;i++)
{
cout<<endl<<"name book no. "<<i<<" : ";getline(cin,books[i].title);
cout<<endl<<"outhor : ";getline(cin,books[i].outhor);
cout<<endl<<"price : ";getline(cin,str_price);
stringstream(str_price)>>books[i].price;
}
}

cout<<endl<<"total "<<counter<<" entered"; // here is froblem


cout<<endl<<endl;
system("PAUSE");
return EXIT_SUCCESS;

}

this code work fine, but i think i cant rely on counter to count books array
though array can grow or shrink unexpected, can anyone halp me to do better way ?
[code] Your code goes here [/code]
though array can grow or shrink unexpected, can anyone halp me to do better way ?
Use std::vector
Why don't you just use a vector for this?
thanks, but i dont know what vector is, ill find out
i didnt finish all this tutorial, i read and practice and found a trouble, just like that, I am just learning about the construct, yet more, until what I have read so I can understand vector?
thanks btw, i read it , but dont get it, i dont even know what class is. may be i need more knowladge before try to learn vector. am i ?, but realy thanks because i dont need to worry about growing or shrinking array, just believe in all of you thats its can be done with vector someday, thanks... all
Topic archived. No new replies allowed.