I was wondering how to make a program to open a specified file just by entering its location. What command do would i use to open it instead of double clicking on the file. Thanks in advance.
rtllz
0
Newbie Poster
Recommended Answers
Jump to PostA file can not be opened by merely giving fstream the path. It also need the filename. And use fstream's open() method. Search the net because there are billions of examples.
Jump to PostWell there isn't much to it
int main() { std::string filename; cout << "Enter a filename\n"; getline(cin, filename); // now open the file ifstream in(filename.c_str()); }
Jump to PostA file can not be opened by merely giving fstream the path. It also need the filename. And use fstream's open() method. Search the net because there are billions of examples.
The filename is part of the "location" of a file :)
Jump to PostSee the code snippet I gave you. getline() will let you enter it at the keyboard. If you don't want to type it then you can do this:
ifstream in("C:\\Documents and Settings\\user\\Desktop\\myfile");
Jump to PostI'm confused as to where im supposed to put the the location of the file such as C:\\Documents and Settings\\user\\Desktop\\myfile ??
you will need a file extension too.
the double
\\
are needed for the direct string input but if youstd::string location = "C:\\folder1\\folder2\\my_file.txt"; …
All 21 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
rtllz
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
jwenting
1,889
duckman
Team Colleague
rtllz
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
tetron
22
Junior Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
rtllz
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
rtllz
0
Newbie Poster
rtllz
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
rtllz
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
rtllz
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
rtllz
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
rtllz
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
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.