Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. fstream

fstream

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++iosquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Selevercin
    wrote on last edited by
    #1

    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.

    N T 2 Replies Last reply
    0
    • S Selevercin

      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.

      N Offline
      N Offline
      Nitron
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • N Nitron

        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

        S Offline
        S Offline
        Selevercin
        wrote on last edited by
        #3

        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.

        N 1 Reply Last reply
        0
        • S Selevercin

          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.

          N Offline
          N Offline
          Nitron
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • S Selevercin

            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.

            T Offline
            T Offline
            Toni78
            wrote on last edited by
            #5

            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

            S 1 Reply Last reply
            0
            • T Toni78

              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

              S Offline
              S Offline
              Selevercin
              wrote on last edited by
              #6

              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.

              T 1 Reply Last reply
              0
              • S Selevercin

                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.

                T Offline
                T Offline
                Toni78
                wrote on last edited by
                #7

                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

                S 1 Reply Last reply
                0
                • T Toni78

                  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

                  S Offline
                  S Offline
                  Sendel
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups