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. to read a file into an array

to read a file into an array

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
3 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.
  • R Offline
    R Offline
    robin700
    wrote on last edited by
    #1

    please tell me how can i read a data file into an array line by line for e.g i have bob 123 mike 456

    M N 2 Replies Last reply
    0
    • R robin700

      please tell me how can i read a data file into an array line by line for e.g i have bob 123 mike 456

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

      use CStdioFile and CStdioFile::ReadString to read one file, and a nice while loop to read each line; put each line that you read into a std::vector<CString >. If you need to split each line into section (name and number), then you will need to use something like strtok. goood luck.

      Watched code never compiles.

      1 Reply Last reply
      0
      • R robin700

        please tell me how can i read a data file into an array line by line for e.g i have bob 123 mike 456

        N Offline
        N Offline
        Niklas L
        wrote on last edited by
        #3

        Using just stl you can do something like:

        ifstream file("file.dat");

        vector lines;
        string line;

        while (getline(file, line))
        lines.push_back(line);

        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