Sign in to follow this  

ifstream

This topic is 4378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey I'm back, this time with a problem with ifstream(). If you don't know already, I'm using c++ on Windows XP. I don't understand exactly how ifstream works. I tried doing this to open a file using the ifstream::open constructor... void open(const char* szName, int nMode = ios::in, int nProt = filebuf::openprot); ------------------------------------------------------------------------- #include <iostream> #include <fstream> using namespace std; ifstream infile; char FILENAME[255]; // Program code... cin >> FILENAME; infile.open(FILENAME,ios::in | ios::nocreate,filebuf::sh_compat); -------------------------------------------------------------------------- but I'm getting back errors that say `nocreate' is not a member of `std::ios' `sh_compat' is not a member of `std::filebuf' I checked the avaliable parameters for the ifstream::open constructor and they are all avaliable arguments to pass, but the compiler gives me errors. Can anyone tell me what is going on?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
include

int main()
{
std::fstream outFile;
outFile.open("someStupidFile.csv", std::ios_base::out);

if(!outFile.is_open())
{
// Error
return -1;
}

outFile <

Share this post


Link to post
Share on other sites
Quote:
Original post by GuitarPlayer0912
Documentation?


Where did you check for valid parameters for open()? By the way, you shouldn't have to worry about the third parameter of open(). Just omit it.

[edit] I'll just give you an example, relating to your previous thread:
#include <iostream>
#include <fstream>
#include <string>

int main() {
using namespace std;

string filename;
cout << "Enter filename: ";
cin >> filename; // You may prefer "getline( cin, filename );"

ifstream fin( filename.c_str() );
if( fin.fail() ) {
// File does not exist.
}
else {
// File exists.
// Ask user if he/she wants to overwrite
}

}



[Edited by - jflanglois on December 16, 2005 10:01:24 PM]

Share this post


Link to post
Share on other sites
I think jflanglois has it right. You are relying on documentation that refers to the old, pre-standard fstream classes. Here, infile.open(FILENAME) is all you really need to write.

Share this post


Link to post
Share on other sites

This topic is 4378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this