Re: Can not create a Vector of Strings
On Tue, 09 Sep 2008 10:12:54 +0200, Fred Zwarts wrote:
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?
Thats array .. oh .. no. and I thought I was giving the maximum number of
elements this vector must have. This is the new version with one error:
int main()
{
const int svec_size = 3;
std::vector<std::string> svec;
std::string user_input;
for( int i = 0; (std::cin >> user_input) || (i != svec_size); ++i )
{
svec[i].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: no matching function for call to
`std::basic_string<char, std::char_traits<char>, std::allocator<char>
::push_back(std::string&)'
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/basic_string.h:795:
note: candidates are: void std::basic_string<_CharT, _Traits,
_Alloc>::push_back(_CharT) [with _CharT = char, _Traits =
std::char_traits<char>, _Alloc = std::allocator<char>] [arnuld@dune ztest]$
Line number 19 is where i did push_back on svec.
--
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming