CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2006
    Posts
    14

    Vector containers

    I am having a problem storing strings into a vector

    I now how to store int into a vector

    vector<int> vecList(10);

    for (int i = 0; i < 10; i++)
    vecList[i] = i;

    If anyone can point me in the right direction that would be great!!!

    Thanks!!!

  2. #2
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863

    Re: Vector containers

    so what is the problem?

    std::vector<std::string> strings
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  3. #3
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211

    Re: Vector containers

    [ Moved Thread ]

    Code:
    #include <iostream>
    #include <string>
    #include <vector>
    
    using std::vector;
    using std::string;
    using std::ostream_iterator;
    
    using std::cout;
    using std::endl;
    
    int main()
    {
    	typedef vector< string > TString;
    	TString		tString;
    
    	tString.push_back("Hello");
    	tString.push_back("World");
    
    	std::copy( tString.begin(), tString.end(), ostream_iterator<string> (cout, "\n"));
    
    	return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured