#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{   
    string f, o, i, file_c, file_d;
    ifstream fin;
    ofstream fout;
    f = "in.txt";
    o = "out.txt";

    cout << "Input filename" << endl;
    cin >> i;

    file_c = i + f;
    file_d = i + o;

    cout << file_c << endl;
    cout << file_d << endl;

    fin.open(file_c);
    fin.close();




    system("PAUSE");
    return EXIT_SUCCESS;
}

The problem im having is getting the file to open.

#include <cstdlib>
file_c = i + f;
file_d = i + o;


The problem im having is getting the file to open.

You cannot concatenate strings this way in C/C++.
Use strcat.

Like strcat(str1, str2);

Hope this helps.

When i tried to concatenate strings using my method, it outputs the correct thing, but when i try to use that variable to open that file it goes in to error. ill try strcat.

i think i figured it out.
i had to use
fin.open(file_c.c_str());
it compiled, so lets see if it reads it correctly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.