Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
opening a file in c++
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="WilliS" data-source="post: 25590"><p>any c++ gurus out there? i need help opening a text file on my desktop called text.txt...this is my code for one of my functions... it has an if the file open fail, than message that it failed...but i can never get it to work... what do i need to type to get to the file on the desktop??</p><p></p><p>void get_test_files(ifstream &in_s, ofstream &out_s) </p><p>// This function asks users to enter the input and output file names from the keyboard.* </p><p>// It will attempt to connect to the files and once successfully connected, it returns the input</p><p>// and output streams to the main.* If it fails to connect to the input or output file, it will terminate the program.</p><p>{</p><p>char originalFile [100];</p><p>cout << "Enter the file you wish to convert (ex: Macintosh HD\\Users\\williamlarrison\\Desktop):";</p><p>cin >> originalFile;</p><p>in_s.open(originalFile);</p><p> if(in_s.fail())</p><p> {</p><p> cout << "Open Failure. Quitting Program";</p><p> cout << originalFile;</p><p> exit(0);</p><p> }</p><p> else</p><p> cout << "WORKED";</p><p>}</p><p></p><p></p><p></p><p>*crosses fingers and hopes someone programs in c++*</p></blockquote><p></p>
[QUOTE="WilliS, post: 25590"] any c++ gurus out there? i need help opening a text file on my desktop called text.txt...this is my code for one of my functions... it has an if the file open fail, than message that it failed...but i can never get it to work... what do i need to type to get to the file on the desktop?? void get_test_files(ifstream &in_s, ofstream &out_s) // This function asks users to enter the input and output file names from the keyboard.* // It will attempt to connect to the files and once successfully connected, it returns the input // and output streams to the main.* If it fails to connect to the input or output file, it will terminate the program. { char originalFile [100]; cout << "Enter the file you wish to convert (ex: Macintosh HD\\Users\\williamlarrison\\Desktop):"; cin >> originalFile; in_s.open(originalFile); if(in_s.fail()) { cout << "Open Failure. Quitting Program"; cout << originalFile; exit(0); } else cout << "WORKED"; } *crosses fingers and hopes someone programs in c++* [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
opening a file in c++
Top