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. How to close file in C++?

How to close file in C++?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestioncareer
5 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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    Yet another "problem" got me stumped. To verify "networking" I use system call such as

    system("vim /etc/hosts");

    It does the job, however, I cannot figure out how to close the file. The standard "vim" way is "Esc :q!" , and it is unclear which character should be "send" via standard console and which ones after responses from vim. Either manually (cin) or as a string starting with "Esc". Cheers

    CPalliniC L 2 Replies Last reply
    0
    • V Vaclav_

      Yet another "problem" got me stumped. To verify "networking" I use system call such as

      system("vim /etc/hosts");

      It does the job, however, I cannot figure out how to close the file. The standard "vim" way is "Esc :q!" , and it is unclear which character should be "send" via standard console and which ones after responses from vim. Either manually (cin) or as a string starting with "Esc". Cheers

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      What kind of verification does vim? I am asking such a question because, I believe, while it is not straightforward closing vim, there could be better alternatives to 'verify networking'.

      In testa che avete, signor di Ceprano?

      S V 2 Replies Last reply
      0
      • V Vaclav_

        Yet another "problem" got me stumped. To verify "networking" I use system call such as

        system("vim /etc/hosts");

        It does the job, however, I cannot figure out how to close the file. The standard "vim" way is "Esc :q!" , and it is unclear which character should be "send" via standard console and which ones after responses from vim. Either manually (cin) or as a string starting with "Esc". Cheers

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        If vim is not in insert or append mode then you can close it by sending ZZ.

        1 Reply Last reply
        0
        • CPalliniC CPallini

          What kind of verification does vim? I am asking such a question because, I believe, while it is not straightforward closing vim, there could be better alternatives to 'verify networking'.

          S Offline
          S Offline
          Stefan_Lang
          wrote on last edited by
          #4

          I wondered about that too: if the point is just to verify that you can access a certain file across a network file path, then trying to open it with fstream::open() should do the job. Whereas, emulating console input that is supposed to be passed into an external process would be kind of tricky, to say the least...

          GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

          1 Reply Last reply
          0
          • CPalliniC CPallini

            What kind of verification does vim? I am asking such a question because, I believe, while it is not straightforward closing vim, there could be better alternatives to 'verify networking'.

            V Offline
            V Offline
            Vaclav_
            wrote on last edited by
            #5

            I am just looking to verify "hosts" names. And I realize that using vim is asking for complications, especially when I actually need to use / select "name" for further processing. vim is bad idea.

            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