Computing.Net > Forums > Programming > c++, unix, and file input

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

c++, unix, and file input

Reply to Message Icon

Name: Air_run
Date: February 3, 2004 at 11:20:02 Pacific
OS: Win XP Pro
CPU/Ram: dual Athlon 2400+, 3/4 of
Comment:

I need to write some code that will allow a user to enter a full path for an input file in UNIX. I've tried declaring a string, having the user enter a path, and passing that string to the .open method. The compiler keeps coming up with an error. Any suggestions??



Sponsored Link
Ads by Google

Response Number 1
Name: Infinite Recursion
Date: February 3, 2004 at 14:36:16 Pacific
Reply:

Would your error happen to be this ... ?

jpsu.cpp:15127: no matching function for call to `fstream::open (string &, ios::open_mode)'
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/../../../../include/g++-3/fstream.h:89: candidates are: void fstream::open(const char *, int, int = 436)


0

Response Number 2
Name: Air_run
Date: February 3, 2004 at 18:33:20 Pacific
Reply:

That looks about right...except that I'm using a different compiler. Other than the path, the rest of the error looks the same.


0

Response Number 3
Name: Infinite Recursion
Date: February 9, 2004 at 06:39:39 Pacific
Reply:

Aaron,

I resolved the problem by converting the string to a character array...

string procFileName = "mydir";
string transactionName = "myfile.dat";
procFileName += transactionName;
char pf[500] = "";
strcpy(pf,procFileName.c_str());
procFile.open(pf,std::ios::out);
...do stuff with file...
procFile.close();


Works great...

IR


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: c++, unix, and file input

C++ file input streaming www.computing.net/answers/programming/c-file-input-streaming/9276.html

C++ - Check for file AND folder www.computing.net/answers/programming/c-check-for-file-and-folder/11957.html

C++: Unix system call and variables www.computing.net/answers/programming/c-unix-system-call-and-variables/7665.html