Path String Concatenation Question.

Posted by Nano HE on Stack Overflow See other posts from Stack Overflow or by Nano HE
Published on 2010-05-19T02:57:56Z Indexed on 2010/05/19 3:20 UTC
Read the original article Hit count: 207

Filed under:
|

Hi. Please see my code below.

ifstream myLibFile ("libs//%s" , line); // Compile failed here ???

I want to combine the path string and open the related file again.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string line;
  ifstream myfile ("libs//Config.txt");  
  // There are several file names listed in the COnfig.txt file line by line.
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
  getline (myfile,line);
  cout << line << endl;
  // Read details lib files based on the each line file name.
  string libFileLine;
  ifstream myLibFile ("libs//%s" , line);  // Compile failed here ???
  if (myLibFile.is_open())
  {
   while (! myLibFile.eof() )
   {
    cout<< "success\n";
   }
   myLibFile.close();
  }


    }
    myfile.close();
  }

  else cout << "Unable to open file"; 

  return 0;
}

Assume my [Config.txt] include the content below. And all the *.txt files located in libs folder.

file1.txt
file2.txt
file3.txt

© Stack Overflow or respective owner

Related posts about c++

Related posts about string