I'm trying to let the user dynamically enter the name for text files that they are reading into my program, as well as what they what the output to be.
I know with C++, that ifstream and ofstream are what's needed and those are working fine.
I do a cin>>input and read it into a char array(cstring). I have included string.h with my includes. Now the .open function requires a cstring as an input. Something like
As is, this works ok but you have to specify the .txt part of the file and I would like to take it a bit further.Code:#include<string.h> inputfile; cout<<"put the name of the file you want to open: "; cin>>inputfile; myfile.open (inputfile);
I want to automate the .txt part, as well as use the input filename as part of the 2 output filenames that I want.
Basically, I want to read in from say: Test1.txt.
For my program I want to only have the user input "Test1", and have my program add the .txt to it before it does the myfile.open part.
I have tried doing:
I put the inputfile into another container because I want to reuse inputfile for the 2 outputs like so:Code:strcopy(inputfile2, inputfile); strcat(inputfile2,".txt"); myfile.open(inputfile2);
Which should give me "Test1.txt" as my input, and "Test1 -translation.txt", and "Test1 -reportfile.txt" as the 3 different filenames. But it's not working right.Code:strcopy(outputfile,inputfile); strcat(outputfile," -translation.txt"); strcopy(reportfile, inputfile); strcat(reportfile," -reportfile.txt"); myfile.open(reportfile); myfile.open(outputfile);
Remember, I have included string.h, and I have also tried it with <cstring>. I'm not really sure what else I can do, is my compiler so old(its not a very up to date linux box) that it doesn't have this function built in?
Every time I compile I get "'strcopy' was not declared in this scope"
The only reason I'm doing it with C strings is because myfile.open(filename.txt) requires it's input to be a C string, otherwise I would use the string container. I could also use the c_str() to convert a C++ string to C, but then I would still run into the same issues using strcopy.
Any help would be appreciated.