Solved

Accessing a File

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now