0
#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.

Edited by mike_2000_17: Fixed formatting

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by hsma
0

#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.

0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.