Can not create a Vector of Strings
Hi Friends,
I hope you have remembered me. Its been a long time since I hung here at
comp.lang.c++. I still remember names like Daniel T., Victor Bazarov,
Erik Wikstrom and many others :) .Good news is that I got a job and I am
earning money and no longer dependent on my old parents. Bad news is that
in these last 6 months , the job which required me to learn C and Socket
Programming, nearly ate all of my time everyday. so I have not touched the
C++ and forgotten the style and feel of it.
Now today, I have started to walk again on C++ and crated a small program.
I can't compile it anyway:
// simple illustration of Std. Lib. Vector
// this program will ask user to input a single word and will store that input
// into a vector and will print it when user have hit the EOF or entered 3 words
#include <iostream>
#include <string>
#include <vector>
int main()
{
const int svec_size = 3;
std::vector<std::string> svec[svec_size];
std::string user_input;
for( int i = 0; (std::cin >> user_input) || (i != svec_size); ++i )
{
svec.push_back( user_input );
}
std:cout << "-------------------------" << std::endl;
for( std::vector<std::string>::const_iterator citer=svec.begin();
citer != svec.end(); ++citer )
{
std::cout << *citer;
}
return 0;
}
================= OUTPUT =========================
[arnuld@dune ztest]$ g++ -ansi -pedantic -Wall -Wextra second.cpp
second.cpp: In function `int main()':
second.cpp:19: error: request for member `push_back' in `svec',
which is of non-class type `std::vector<std::string,
std::allocator<std::string> >[3]' second.cpp:22: error: `cout' was not
declared in this scope second.cpp:24: error: request for member `begin' in
`svec', which is of non-class type `std::vector<std::string,
std::allocator<std::string> >[3]' second.cpp:25: error: request for member
`end' in `svec', which is of non-class type `std::vector<std::string,
std::allocator<std::string> >[3]' second.cpp:22: warning: unused variable
'cout' second.cpp:22: warning: label `std' defined but not used
[arnuld@dune ztest]$
--
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming