CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #3
    Join Date
    Apr 2008
    Posts
    118

    Re: problem using vector for file directory

    As an aside to your primary question, that call to main() at the end of your function void list(vector<string>files) - what is that for? Why are you calling main from within a function?

    I think we might need to see your main() function to work out the problem. The code below works as expected.

    Code:
    #include <vector>
    #include <string>
    #include <iostream>
    
    
    int main()
    {
      
      using std::vector;
      using std::string;
      using std::cout;
      
    
    
      vector<string> files;
      files.push_back("C:/bills/default.txt");
      files.push_back("C:/bills/jan.txt");
      files.push_back("C:/bills/feb.txt");
      files.push_back("C:/bills/mar.txt");
      files.push_back("C:/bills/april.txt");
      files.push_back("C:/bills/may.txt");
      files.push_back("C:/bills/june.txt");
      files.push_back("C:/bills/july.txt");
      files.push_back("C:/bills/aug.txt");
      files.push_back("C:/bills/sept.txt");
      files.push_back("C:/bills/oct.txt");
      files.push_back("C:/bills/nov.txt");
      files.push_back("C:/bills/dec.txt");
      string file;
                       
      file=files[0];
      
      cout << file;
      return 0;
      
    }
    Last edited by Moschops; March 4th, 2011 at 11:24 AM.

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