?
Solved

Accessing a File

Posted on 2000-05-13
2
Medium Priority
?
192 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 300 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

Technology Partners: 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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 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