Q:

combining strings

I'm trying to combine strings to input text files. My code looks like this:
`#include <iostream>
#include <sstream>
#include <fstream>
#include <string>

using namespace std;

int main(){
int year;
string line;
string fileName;

for (int i=1880; i<2012; i++){
    stringstream ss;
    ss << year;

fileName = string("yob") + string(year) + string(".txt");

ifstream ifile(fileName.c_str());
getline(ifile,line);
cout << line << endl;
ifile.close();
}

}`

The text files look like "yob1880.txt" <-- that's the first text file and it goes all the way to "yob2011.txt". I want to input the text files one by one, but combining these three string types doesn't work it gives me an error saying invalid conversion from int to const char*. 
Any thoughts on the problem? Thanks!

A:

You should get it from the stringstream. You're almost there but this is what you should do instead:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>

using namespace std;

int main(){
int year;
string line;
string fileName;

for (int i=1880; i<2012; i++){
    year = i; //I'm assuming this is what you meant to use "year" for
    stringstream ss;
    ss << year; //add int to stringstream

string yearString = ss.str(); //get string from stringstream

fileName = string("yob") + yearString + string(".txt");

ifstream ifile(fileName.c_str());
getline(ifile,line);
cout << line << endl;
ifile.close();
}

}

