get input and open in string

Hi guys my first post here as i find this site too much helpful :)

I am trying to read write and edit txt files in turboc++ I want to make a program that gets input suppose cout<<"Enter file name "; cin>>name;
and input given is abc.txt

now i want it to goto directory and open that file for editing .....

please help :) it will be appreciated
Last edited on
I have made program
Problem is that....

the directory is by programmer i want user to enter directory and open it....
You'd probably want something like this:

1
2
3
4
5
6
7
8
9
std::fstream myFile;
std::string  myStringFileName;

std::cout<<"Enter filename\n";
std::getline(std::cin, myStringFileName);

myFile.open(myStringFileName.c_str());
//do write/read stuff
myFile.close();


Take note that this isn't the best way to do this. There is probably a better way to do this by using class constructors/destructors for exception safety.
Last edited on
Topic archived. No new replies allowed.