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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Reading a File

Reading a File

Scheduled Pinned Locked Moved Managed C++/CLI
ioswinformstutorial
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.
  • N Offline
    N Offline
    newkid
    wrote on last edited by
    #1

    Hi I was wondering to read a file in and display this file in a listbox. I know how to do this in the console programming but not sure how to do this in windows forms. This how I do it in console programming. Just not sure how to do this in windows forms. int openFile() { ifstream filex; filex.open ("test.txt", ios::in ); if (filex.is_open()) { filex.seekg (0, ios::end); size = filex.tellg(); filemem = new char [size]; filex.seekg (0, ios::beg); filex.read (filemem, size); ifstream fin("test.txt",ios ::in); cout << cin.rdbuf(); filex.close(); } else { cout << "Unable to open file"; } return 0; } Thanks The New kid

    M 1 Reply Last reply
    0
    • N newkid

      Hi I was wondering to read a file in and display this file in a listbox. I know how to do this in the console programming but not sure how to do this in windows forms. This how I do it in console programming. Just not sure how to do this in windows forms. int openFile() { ifstream filex; filex.open ("test.txt", ios::in ); if (filex.is_open()) { filex.seekg (0, ios::end); size = filex.tellg(); filemem = new char [size]; filex.seekg (0, ios::beg); filex.read (filemem, size); ifstream fin("test.txt",ios ::in); cout << cin.rdbuf(); filex.close(); } else { cout << "Unable to open file"; } return 0; } Thanks The New kid

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      There's lots of sample code in the MSDN documentation, available right from Visual Studio. For example: File and Stream I/O[^] Common I/O Tasks[^] How to: Read Text from a File[^] ListBox Class (System.Windows.Forms)[^] ListBox::ObjectCollection::Add Method[^] Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      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