You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
688 B
C++

Fig01_10.cpp - Illustration of using the vector class
#include <iostream.h>
#include "vector.h" // vector (our version, in Appendix B)
#include "mystring.h" // string (our version, in Appendix B)
int main( )
{
vector<string> v( 5 );
int itemsRead = 0;
string x;
while( cin >> x )
{
if( itemsRead == v.size( ) )
v.resize( v.size( ) * 2 );
v[ itemsRead++ ] = x;
}
for( int i = itemsRead - 1; i >= 0; i-- )
cout << v[ i ] << endl;
return 0;
}