   'Run as an Administrator '
  Hey,I'm opening .txt file in my code.But when I put my program into Program Files folder, the file doesn't open.When I 'run as an Administrator' it works fine.I don't want to run it as an administrator...So what should I do?This is how I open the file:fstream wczytywanie("fonty.txt" );  wczytywanie<<noskipws;   while(getline(wczytywanie, tekst_linijka))  {
  If you only want to read from the file, perhaps using ifstream (read-only stream) instead helps. (fstream opens the file both for reading and writing at the same time by default, and it is the latter that should be causing problems.)If you also want to write to the file, simply don't put either your program or the file in a folder that is restricted for regular users.   ;  Your not supposed to be writting to files in the program files folder. You can read them (make sure you specify read and not read/write when opening) but can't write them unless your admin. Took me ages to figure out why my shaders wouldn't load :P.Your either going to have to use a different folder (many program seem to install right into c:/ now) or save your files into application data or whatever the folder is What OS is this? vista or win 7? I think they both follow the same rules for program files but not tried win7.   ;  When I had used ifstream I received errors like:Quote:error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::ifstream'1>   C:\Program Files\Microsoft Visual Studio 9.0\VC\include\string(537) : see declaration of 'std::operator <<'....Don't know why...////The 'program' which I mentioned is actually a game so some users must have possibility to install it into Program Files I guess.   ;  What is the file for? Do you need to write to it, or can you just read from it? If you only need to read from it, use an ifstream as others mentioned. If you need to write to it, then the file cannot be located under Program Files, because all files in that directory are write-protected by the operating system. You will need to put it somewhere else, like in the user's My Documents directory (I don't know what the actual "correct" directory is for this problem on Windows, sorry).   ;Quote:Original post by MoriquendiWhen I had used ifstream I received errors like:Quote:error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::ifstream'1>   C:\Program Files\Microsoft Visual Studio 9.0\VC\include\string(537) : see declaration of 'std::operator <<'....Don't know why...////The 'program' which I mentioned is actually a game so some users must have possibility to install it into Program Files I guess.Yes, well, if you read the error you would note that it mentions operator <<. Which is available only to ostreams. If you're attempting to use operator << on an object of type ifstream, then you're quickly going to find that that doesn't work.   ;  getenv("APPDATA") gives you the path to a directory where user-run programs can read/write to files.You should create a directory in APPDATA (probably the program's name), then you use APPDATA/name to store all files the program needs to write to.   ;Quote:Original post by marsonggetenv("APPDATA") gives you the path to a directory where user-run programs can read/write to files.You should create a directory in APPDATA (probably the program's name), then you use APPDATA/name to store all files the program needs to write to.That's a bad idea, mainly because localization will completely break that. The proper way to do it would be to use SHGetFolderPath (SHGetKnownFolderPath on vista, but SHGetFolderPath wraps that) and specify CSIDL_APPDATA for the path you wish to request. You can use CSIDL_COMMON_APPDATA for data that the application requires that is non-user specific. CSIDL_LOCAL_APPDATA is the best one to use though if your application might be run on roaming clients and your data does not need to roam (otherwise the data bloats the roaming profile).   ;Quote:Original post by WashuYes, well, if you read the error you would note that it mentions operator <<. Which is available only to ostreams. If you're attempting to use operator << on an object of type ifstream, then you're quickly going to find that that doesn't work.It looks like he only wants operator<< in order to set noskipws on the stream.Hint: You can set this behaviour with operator>> instead, when you have an input stream (such as ifstream). :)   ;Quote:Original post by WashuThat's a bad idea, mainly because localization will completely break that. The proper way to do it would be to use SHGetFolderPath (SHGetKnownFolderPath on vista, but SHGetFolderPath wraps that) and specify CSIDL_APPDATA for the path you wish to request. You can use CSIDL_COMMON_APPDATA for data that the application requires that is non-user specific. CSIDL_LOCAL_APPDATA is the best one to use though if your application might be run on roaming clients and your data does not need to roam (otherwise the data bloats the roaming profile).%APPDATA% does not break localization, it returns the correct path to C:\Users\<username>\AppData\Roaming (for Vista/7, or whatever the localized path is on Windows XP).You might be thinking about using %USERPROFILE% and appending Application Data (or similar), which would break localization.