Jump to content
  • Advertisement
Sign in to follow this  
GuitarPlayer0912

ifstream

This topic is 4747 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
Advertisement
What documentation are you using, because as far as I know, ios::nocreate is pre-standard? open() will fail if the file does not exist.


jfl.

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
Guest Anonymous Poster
It removed some stuff.

#include

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!