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 Postyou will need a file extension too.
Maybe, and maybe not. Depends on if the file has an extension, and what the actual extension is. Could be *.txt, for might also be something else, or nothing at all. Under MS-Windows XP or newer and *nix it may even have multiple …
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,905 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.