Thread: Reading file into edit - losing new lines

  1. #1
    Registered User eam's Avatar
    Join Date
    Oct 2003
    Posts
    53

    Reading file into edit - losing new lines

    Here's the code I worte. It works but the text from the file is put into the edit in one big block. How could I modify it to solve the problem?

    Code:
    BOOL ReadIntoEdit(HWND hwndEdit, PTSTR pstrFileName) {
    ifstream in(pstrFileName);
    
    if (!in) {
    MessageBox (NULL, "File could not be read." , "Error!", 0 | MB_ICONHAND | MB_SETFOREGROUND);
    return FALSE;
    }
    
    string fileContents, line;
    while(getline(in, line))
    fileContents += line + "\n";
    
    char *convertedContents;
    convertedContents = new char[fileContents.size()+1];
    fileContents.copy(convertedContents,fileContents.size());
    
    SetWindowText(hwndEdit, convertedContents);
    
    return TRUE;
    }
    Last edited by eam; 11-08-2003 at 10:24 AM.

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    8
    You need a \r as well as a \n to move down a line in an edit box

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Try using "\r\n" or "\n\r" as your newline - I forget which.

    gg

  4. #4
    Registered User eam's Avatar
    Join Date
    Oct 2003
    Posts
    53
    Ah, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question regarding reading data from file into arrays
    By vutek0328 in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 09:20 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Reading lines in from a file?
    By JarJarBinks in forum C++ Programming
    Replies: 8
    Last Post: 08-30-2004, 09:46 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM