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. C / C++ / MFC
  4. Trying to manipulate CStdioFile

Trying to manipulate CStdioFile

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • S Offline
    S Offline
    Stevieslu
    wrote on last edited by
    #1

    I am trying to replace spaces with newlines \n's in a file to create a single column then I can read the file using ReadString to get one value at a time but it doesn't work. It still thinks the file has the original set-up of rows and columns instead of just a single column. Can anyone explain why? Here is the code... CString cFilename = lpszPathName; CStdioFile fDataFile,fDataCol; CString szValue; CString szRow; fDataFile.Open(lpszPathName, CFile::modeRead); fDataFile.ReadString(szRow); int nFirst = szRow.Replace(" ","\n"); while(fDataFile.ReadString(szRow)) { int nCol = szRow.Replace(" ","\n"); } fDataFile.Close(); fDataCol.Open(lpszPathName, CFile::modeRead); BOOL b = fDataCol.ReadString(szValue); if(TRUE == b) { m_nRows = atoi(szValue); } b = fDataCol.ReadString(szValue); if(TRUE == b) { m_nColumns = atoi(szValue); } m_nValues = (m_nRows*m_nColumns); m_GraphData.SetSize(m_nRows); int nRowCount; int nColumnCount; for (nRowCount = 0; nRowCount

    A 1 Reply Last reply
    0
    • S Stevieslu

      I am trying to replace spaces with newlines \n's in a file to create a single column then I can read the file using ReadString to get one value at a time but it doesn't work. It still thinks the file has the original set-up of rows and columns instead of just a single column. Can anyone explain why? Here is the code... CString cFilename = lpszPathName; CStdioFile fDataFile,fDataCol; CString szValue; CString szRow; fDataFile.Open(lpszPathName, CFile::modeRead); fDataFile.ReadString(szRow); int nFirst = szRow.Replace(" ","\n"); while(fDataFile.ReadString(szRow)) { int nCol = szRow.Replace(" ","\n"); } fDataFile.Close(); fDataCol.Open(lpszPathName, CFile::modeRead); BOOL b = fDataCol.ReadString(szValue); if(TRUE == b) { m_nRows = atoi(szValue); } b = fDataCol.ReadString(szValue); if(TRUE == b) { m_nColumns = atoi(szValue); } m_nValues = (m_nRows*m_nColumns); m_GraphData.SetSize(m_nRows); int nRowCount; int nColumnCount; for (nRowCount = 0; nRowCount

      A Offline
      A Offline
      Alvaro Mendez
      wrote on last edited by
      #2

      Without looking at your code I'm going to guess that it's because you need to use \r\n instead of just \n. Try that and see if it makes a difference. Regards, Alvaro

      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