Fred Zwarts
9/9/2008 8:13:00 AM
"arnuld" <sunrise@invalid.address> wrote in message news:pan.2008.09.09.08.02.52.279850@invalid.address...
> 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];
What do you want to do with the [svec_size]?
You are now creating an array of three vectors. Why not creating just one vector?
std::vector<std::string> svec;
> std::string user_input;
>
> for( int i = 0; (std::cin >> user_input) || (i != svec_size); ++i )
> {
> svec.push_back( user_input );
If you want to use the push_back function, you need to specify on which vector of the three vectors in the array.
You cannot push it on all vectors in the array at once.
Did you mean
svec[i].push_back( user_input );
> }
>
> std:cout << "-------------------------" << std::endl;
>
> for( std::vector<std::string>::const_iterator citer=svec.begin();
> citer != svec.end(); ++citer )
Again, the begin and end functions cannot be applied to the array of vectors.
Select one of the three vectors, or don't use an array.
> {
> 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
>