fstream
-
How come I get the following errors on my MFC dialog app? I have included fstream.h and I have used code like this before. Why is it not working here?
void CTestDlg::OnTimer(UINT nIDEvent) { fstream file; file.open("Run.txt", ios::out); CDialog::OnTimer(nIDEvent); }
error C2065: 'fstream' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'file' error C2065: 'file' : undeclared identifier error C2228: left of '.open' must have class/struct/union type error C2653: 'ios' : is not a class or namespace name error C2065: 'out' : undeclared identifier Error executing cl.exe. Thanks, Selevercin If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
-
How come I get the following errors on my MFC dialog app? I have included fstream.h and I have used code like this before. Why is it not working here?
void CTestDlg::OnTimer(UINT nIDEvent) { fstream file; file.open("Run.txt", ios::out); CDialog::OnTimer(nIDEvent); }
error C2065: 'fstream' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'file' error C2065: 'file' : undeclared identifier error C2228: left of '.open' must have class/struct/union type error C2653: 'ios' : is not a class or namespace name error C2065: 'out' : undeclared identifier Error executing cl.exe. Thanks, Selevercin If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
-
it's:
ifstream file // for input
or
ofstream file // for output
if that doesn't work, try:
std:: (file == input ? i : o)fstream;
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
Hi Nitron. I've already tried the ofstream (it's output), but with no success. I just tried your "if that doesn't work" also with no success. I got the following errors (*note* I copied your code exactly): error C2653: 'std' : is not a class or namespace name error C2589: '(' : illegal token on right side of '::' error C2143: syntax error : missing ';' before '::' Error executing cl.exe. I've had my previous way work before, but without using MFC. Any ideas? If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
-
Hi Nitron. I've already tried the ofstream (it's output), but with no success. I just tried your "if that doesn't work" also with no success. I got the following errors (*note* I copied your code exactly): error C2653: 'std' : is not a class or namespace name error C2589: '(' : illegal token on right side of '::' error C2143: syntax error : missing ';' before '::' Error executing cl.exe. I've had my previous way work before, but without using MFC. Any ideas? If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
You neet to include:
#include "fstream.h"
and try:
std::ifstream file;
(my last line was pseudo-code, telling you to put "i" or "o" depending on if it's an input file or not. Sorry :rolleyes: - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
-
How come I get the following errors on my MFC dialog app? I have included fstream.h and I have used code like this before. Why is it not working here?
void CTestDlg::OnTimer(UINT nIDEvent) { fstream file; file.open("Run.txt", ios::out); CDialog::OnTimer(nIDEvent); }
error C2065: 'fstream' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'file' error C2065: 'file' : undeclared identifier error C2228: left of '.open' must have class/struct/union type error C2653: 'ios' : is not a class or namespace name error C2065: 'out' : undeclared identifier Error executing cl.exe. Thanks, Selevercin If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
-
you are probably doing this: #include <fstream.h> #include "stdafx.h" try this: #include "stdafx.h" #include <fstream.h> // Afterall I realized that even my comment lines have bugs
Wow! Thanks! That fixed it! I know the order of headers matters, but is there a simple reason why this worked? Thanks, Selevercin If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
-
Wow! Thanks! That fixed it! I know the order of headers matters, but is there a simple reason why this worked? Thanks, Selevercin If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
The compiler uses stdafx.cpp to generate a precompiled header file substituting it for all # include's in the # include stdafx.h directive. The header stdafx.h should be at the top of all headers because the compiler ignores any # include directives before stdafx.h. // Afterall I realized that even my comment lines have bugs
-
The compiler uses stdafx.cpp to generate a precompiled header file substituting it for all # include's in the # include stdafx.h directive. The header stdafx.h should be at the top of all headers because the compiler ignores any # include directives before stdafx.h. // Afterall I realized that even my comment lines have bugs
if you don't want to include stdafx.h try this: go to Project->Settings->C/C++->Project Options and search for: "
"/Yu"stdafx.h"
" and replace it by "" (nothing) :laugh: (that means kick it !) and you don't need to include stdafx.h :wtf:Sendel
The only place for millions of bugs is the Rainforest