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. #define and Streams

#define and Streams

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
2 Posts 2 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.
  • C Offline
    C Offline
    CreepingFeature
    wrote on last edited by
    #1

    Hi everyone, especialy those nice gents who actualy answer the questions! ( Ladies? :laugh: ) I know that you can #define fileName "myFile.txt" a string in the globals area, and when you need to you can stream.open(fileName) so you wont have to write the file name every time you open a stream. My question is this can the same logic be used to define the actual stream for example #define ifstream inFileStream so that I wont have to declare the streams inside functions that need to use them. So that the only line relating to a stream in the function would be inFileStream.open(fileName). This should also remove the need to pass the streams to functions since I will be able to open and close them any where any time. Thanks in advance!

    M 1 Reply Last reply
    0
    • C CreepingFeature

      Hi everyone, especialy those nice gents who actualy answer the questions! ( Ladies? :laugh: ) I know that you can #define fileName "myFile.txt" a string in the globals area, and when you need to you can stream.open(fileName) so you wont have to write the file name every time you open a stream. My question is this can the same logic be used to define the actual stream for example #define ifstream inFileStream so that I wont have to declare the streams inside functions that need to use them. So that the only line relating to a stream in the function would be inFileStream.open(fileName). This should also remove the need to pass the streams to functions since I will be able to open and close them any where any time. Thanks in advance!

      M Offline
      M Offline
      markkuk
      wrote on last edited by
      #2

      No. #define causes simple text subsititution before actual compilation. ifstream.open("myFile.txt") isn't valid C++ syntax.

      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