Solved

Accessing a File

Posted on 2000-05-13
2
190 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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

749 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