Thread: Reading lines in from a file?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    45
    Here are some other helpful things in case you need them:

    Code:
    
    int last_position = stringname.rfind("\");
    int length_of_path = stringname.length() - (last_position + 1);
    string path = stringname.substr(last_position + 1, length_of_path);

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    \ is one of those special characters you need to use an escape sequence for, i.e. use \\ instead of just \.

    Quote Originally Posted by quizkiwi
    Here are some other helpful things in case you need them:

    Code:
    
    int last_position = stringname.rfind("\");
    int length_of_path = stringname.length() - (last_position + 1);
    string path = stringname.substr(last_position + 1, length_of_path);
    Or just simply:

    Code:
    string path = stringname.substr(stringname.rfind("\\")+1);
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    ok thank you that was very helpful, one question though im use
    char [] to store my getline, because getline wouldnt accept string
    variables, i shoudl have thought of using string, because i
    was aware of those commands, however what im nto aware of
    is the best way to read into a string, if i remember correctly,
    read() will do it, but it reads so many characters and since im not
    sure of each lines lenght at run time, it may read to far or to short.
    with that said my question would be, can read() take a delimiter
    or is there a better way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Reading file into edit - losing new lines
    By eam in forum Windows Programming
    Replies: 3
    Last Post: 11-08-2003, 01:07 PM
  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