Hello people,
I'm having a problem I hope you can help me with. I'm writing a program which does the following:
1. reads a .txt file that contains filenames and puts the filenames into a vector as strings
2. walks through the vector entries and for each file, opens the file, reads each line, adds the filename at the end of each line and writes the lines to a new file (which is nothing more thatn the same old file, with the filename added at the end of each line).
here is a beginning to my source code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main ()
{
vector<string> bnamen;
string regel;
ifstream lijst("dirlst.txt", ios::in);
while (getline(lijst, regel)) {
bnamen.push_back(regel);
}
for (int i=0;i<bnamen.size();i++){
cout<<bnamen<<endl;
}
string regel2;
** ifstream invoer((bnamen[0]), ios::in);
while(getline(invoer, regel2)){
cout<<regel2<<endl;
}
invoer.close();
lijst.close();
cin.get();
return 0;
}
The line marked with ** is where there is an error. Apparently I can't use a string as a filename to be opened with ifstream. As soon as put the double qoutes (like "bnamen[0]") it doesn't show up as an error, but of course that is not the correct filename. I use Microsoft Developer Studio, it doesn't give explanation when there are errors, so I have no detailed error description.
I hope that someone can help me!
I'm having a problem I hope you can help me with. I'm writing a program which does the following:
1. reads a .txt file that contains filenames and puts the filenames into a vector as strings
2. walks through the vector entries and for each file, opens the file, reads each line, adds the filename at the end of each line and writes the lines to a new file (which is nothing more thatn the same old file, with the filename added at the end of each line).
here is a beginning to my source code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main ()
{
vector<string> bnamen;
string regel;
ifstream lijst("dirlst.txt", ios::in);
while (getline(lijst, regel)) {
bnamen.push_back(regel);
}
for (int i=0;i<bnamen.size();i++){
cout<<bnamen<<endl;
}
string regel2;
** ifstream invoer((bnamen[0]), ios::in);
while(getline(invoer, regel2)){
cout<<regel2<<endl;
}
invoer.close();
lijst.close();
cin.get();
return 0;
}
The line marked with ** is where there is an error. Apparently I can't use a string as a filename to be opened with ifstream. As soon as put the double qoutes (like "bnamen[0]") it doesn't show up as an error, but of course that is not the correct filename. I use Microsoft Developer Studio, it doesn't give explanation when there are errors, so I have no detailed error description.
I hope that someone can help me!