Solved

Accessing a File

Posted on 2000-05-13
2
191 Views
Last Modified: 2010-04-02
The following code is part of what I have at the moment:
while (!Done)
{
   string FileName = FindDat.cFileName;
   FileList.push_back(FileName);
   Done = !FindNextFile(FndHnd, &FindDat);
}
if (FndHnd)
   FindClose(FndHnd);
const int ItmCnt = FileList.size();
if (ItmCnt<12)
{
      for (int i=0; i<11; ++i)
      {
            gotoxy(menux, ++menuy);
            if (i<ItmCnt)
                  cout << "* " << FileList[i];
            if (i>=ItmCnt)
                  cout << "* -EMPTY SLOT-" << endl;
      }
      x-=13;
      y+=2;
      char *barrier={"T08;B18"};
      movecursor(&x,&y,0,1,barrier,0,'\0','\0','\0', player);
      if (y-8<ItmCnt)
      {
            char ch;
            ifstream fin(FileList[y-8]);
            while (fin.get(ch))
            {
                  cout << char(ch);
            }
            fin.close();
      }

The part I'm having trouble is when I try to read the file.  This part: ifstream fin(FileList[y-8]); doesn't seem to work, since I'm sending in a vector instead of a char.  The strcpy doesn't seem to work either.  Is there any way of copying a vector <string> to a char?  Or, is there another workaround for this?
0
Comment
Question by:junkyboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
KangaRoo earned 75 total points
ID: 2806599
Looks like you are using
vector<sting> FileList;
Then the problem is that FileList[y-8] returns a string while ifstream's constructor expects a char* (c-style) string. You can obtain the char* string from a string class object by it;s member function c_str(). So
ifstream fin(FileList[y-8].c_str());
might work here.
0
 

Author Comment

by:junkyboy
ID: 2806602
Thanks!  It worked perfectly!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question