Pulling text from a txt file to a c string.

Discussion in 'C++' started by foenotes@googlemail.com, Jan 11, 2007.

  1. Guest

    hi i have a sentance in a .txt file and would like to pull it out from
    the txt file and assign it to a cstring. so the user only has to edit
    the txt file to change the sentance.

    how do i do this.

    im a complete novice and using vc++ 2005
    , Jan 11, 2007
    #1
    1. Advertising

  2. wrote:
    > hi i have a sentance in a .txt file and would like to pull it out from
    > the txt file and assign it to a cstring. so the user only has to edit
    > the txt file to change the sentance.
    >
    > how do i do this.
    >
    > im a complete novice and using vc++ 2005


    Use 'fopen' and 'fgets'. If you have to use C++, use 'ifstream' and
    'getline' (into a std::string), then use the c_str member to extract
    the C string out of the C++ string.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jan 11, 2007
    #2
    1. Advertising

  3. Ransome Guest

    wrote:
    > hi i have a sentance in a .txt file and would like to pull it out from
    > the txt file and assign it to a cstring. so the user only has to edit
    > the txt file to change the sentance.
    >
    > how do i do this.
    >
    > im a complete novice and using vc++ 2005


    What Victor said, only a small note that there may be a '\n' character
    (that's new line) you have to watch out for if you want to include the
    sentence in the middle of, say, a paragraph (like an adlibs thing).
    You'll either want to remove this character (it's at the last position
    in your string/char array) or exclude it from the variable it in your
    read in.
    Ransome, Jan 11, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    12
    Views:
    974
    Steve
    Nov 18, 2005
  2. Sameen
    Replies:
    2
    Views:
    425
    Victor Bazarov
    Aug 29, 2005
  3. Jochen Brenzlinger
    Replies:
    7
    Views:
    5,488
    Roedy Green
    Sep 15, 2011
  4. Matthew Kitchin \(Usenet/Lists\)

    Multiple pages pulling form a single text file

    Matthew Kitchin \(Usenet/Lists\), Jul 9, 2007, in forum: ASP General
    Replies:
    2
    Views:
    105
    Adrienne Boswell
    Jul 11, 2007
  5. Replies:
    17
    Views:
    281
    Tad McClellan
    Mar 10, 2006
Loading...

Share This Page