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 create a VC program to read text

How to create a VC program to read text

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorial
5 Posts 3 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.
  • H Offline
    H Offline
    harshsingh
    wrote on last edited by
    #1

    :((I am new to the field of VC++....can anyone please tell me as how to create a program that reads a text file, line by line....and if possible how to read each line starting from a particular character to a specified number(of characters)

    K P 2 Replies Last reply
    0
    • H harshsingh

      :((I am new to the field of VC++....can anyone please tell me as how to create a program that reads a text file, line by line....and if possible how to read each line starting from a particular character to a specified number(of characters)

      K Offline
      K Offline
      keegan
      wrote on last edited by
      #2

      one place to start would be to look at msdn.microsoft.com for iostream and fstream. *.* cin >> knowledge;

      H 1 Reply Last reply
      0
      • H harshsingh

        :((I am new to the field of VC++....can anyone please tell me as how to create a program that reads a text file, line by line....and if possible how to read each line starting from a particular character to a specified number(of characters)

        P Offline
        P Offline
        PremL
        wrote on last edited by
        #3

        Consider using a CStdioFile for reading your file. Construct an instance of the class for the file you want to read from. You can call the ReadString method on it to get a line of text from your file into a CString. Then you can make use of all the methods of CString to get to only the part of the line in the string you are interested in. Technically you are reading the whole line. You then parse the string for what you need. Lorenz Prem Microsoft Corporation

        1 Reply Last reply
        0
        • K keegan

          one place to start would be to look at msdn.microsoft.com for iostream and fstream. *.* cin >> knowledge;

          H Offline
          H Offline
          harshsingh
          wrote on last edited by
          #4

          Hi! Keegan I realy don't understand what you wanted to say...was just going through what you told me , but to no avail.....

          K 1 Reply Last reply
          0
          • H harshsingh

            Hi! Keegan I realy don't understand what you wanted to say...was just going through what you told me , but to no avail.....

            K Offline
            K Offline
            keegan
            wrote on last edited by
            #5

            http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/html/\_iostream\_fstream.3a3a.fstream.asp thats an insane description of fstream. I'll show you an example of one way to write to files here:

            string filename = "data.txt";      //the name of the file we want to input from / output to
            	ifstream inFile(filename.c_str());    //'sets up' input from a file
            	ofstream Out;                        //sets up output to a file
            
                    //input a word from a file:
                    string word;
                    inFIle >> word;
            
                    //output that word to a file:
                    Out << word;
            

            ifstream and ofstream are more or less identical in terms of use to cin and cout. Once you define the input and output streams, they work the exact same way (more or less). If you have any more questions, feel free to email me. *.* cin >> knowledge;

            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