LoadFromFile() from a txt

This is a discussion on LoadFromFile() from a txt within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm a little confused about using LoadFromFile(). I want to load a line of text from a .txt file ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    3

    LoadFromFile() from a txt

    Hi,

    I'm a little confused about using LoadFromFile().
    I want to load a line of text from a .txt file and display it (at the click of a button on the form in an edit box or a label. When the button is clicked again, the next line of text will appear.

    I've spent countless hours looking through library books (Borland c++ builder unleased, Sams teach yourself Borland c++ in 14 days, Borland C++ compliers guide and others)
    I have also spent a lot of time looking at various online tutorials, experimenting with various examples etc. but I am still unsure how to use LoadFromFile() (what the code would look like).

    Thanks.


  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    Ok 2 things -

    1. Show us what you have so far to clarify LoadFromFile(); - do you have some code?

    2. I don't know if it will help, but another way you could do it is with the file i/o commands found in this tutorial.

    See if that helps.

    Kermi3
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    3
    Thanks Kermi3,

    I haven't got much in the way of code at the moment, but that tutorial looks very useful.
    I assumed that I needed LoadFromFile(), but looking at it, I probably don't.

    cheers!


  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    LoadFromFile sounds like part of the Borland class library. Is it?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    3
    Yes, I think it could be part of the class library. I think I read a few tutorials on various sites which had references to LoadFromFile(), and since Load from file was what I need to do, I just assumed that it was what I needed.

    One thing I'm not sure of about the tutorial you directed me to Kermi3,
    is where the example.txt file needs to be?
    do I need to create this prior to running the program, or does it create automatically?
    Where does the example.txt file need to be?
    In the same directory as the program?
    how can I specify which directory it looks in for example.txt, so I can put it in another directory?
    backslash doesn't seem to be valid?

    Thanks.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    26
    In the example given you do not need to creat 'examples.txt' because it will be created at run time. When you use the string literal "examples.txt" it tell the program to open a file called examples.txt which is located in the same directory as the program. If the file "examples.txt" does not exist, the program will creat "examples.txt". The reason that it appers that you are having problems with backslash is because it is considered part of what is called an escape sequance. MSDN says the following about escape sequances.

    Escape Sequences
    Character combinations consisting of a backslash (\) followed by a letter or by a Escape Sequences
    Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called “escape sequences.” To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences. An escape sequence is regarded as a single character and is therefore valid as a character constant.

    Escape sequences are typically used to specify actions such as carriage returns and tab movements on terminals and printers. They are also used to provide literal representations of nonprinting characters and characters that usually have special meanings, such as the double quotation mark ("). Table 1.4 lists the ANSI escape sequences and what they represent.

    Note that the question mark preceded by a backslash (\?) specifies a literal question mark in cases where the character sequence would be misinterpreted as a trigraph. See Trigraphs for more information.

    Table 1.4 Escape Sequences

    Escape Sequence Represents
    \a Bell (alert)
    \b Backspace
    \f Formfeed
    \n New line
    \r Carriage return
    \t Horizontal tab
    \v Vertical tab
    \' Single quotation mark
    \" Double quotation mark
    \\ Backslash
    \? Literal question mark
    \ooo ASCII character in octal notation
    \xhhh ASCII character in hexadecimal notation


    Microsoft Specific —>

    If a backslash precedes a character that does not appear in Table 1.4, the compiler handles the undefined character as the character itself. For example, \x is treated as an x.

    END Microsoft Specific

    Escape sequences allow you to send nongraphic control characters to a display device. For example, the ESC character (\033) is often used as the first character of a control command for a terminal or printer. Some escape sequences are device-specific. For instance, the vertical-tab and formfeed escape sequences (\v and \f) do not affect screen output, but they do perform appropriate printer operations.

    You can also use the backslash (\) as a continuation character. When a newline character (equivalent to pressing the RETURN key) immediately follows the backslash, the compiler ignores the backslash and the newline character and treats the next line as part of the previous line. This is useful primarily for preprocessor definitions longer than a single line. For example:

    #define assert(exp) \
    ( (exp) ? (void) 0:_assert( #exp, __FILE__, __LINE__ ) )


    --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources.
    Thus if you wanted to use the file "c:\data\mydata.txt", you would have to type "c:\\data\\mydata.txt" for the file that you wanted to load.

    -JLBShecky
    System
    OS - Microsoft Windows XP Pro
    CPU - AMD Athlon XP 2600+
    Mother Board - Abit KV7
    RAM - 512 Mb DDR (333)

    C++
    Microsoft Visual Studio Pro. 6.0
    MSDN July 2001

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    wow. believe it or not this helped me alot, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading txt files
    By Tbrez in forum C Programming
    Replies: 6
    Last Post: 03-10-2009, 04:40 PM
  2. Replies: 21
    Last Post: 06-16-2008, 03:44 PM
  3. Reading a txt file into a struct problem
    By Swerve in forum C++ Programming
    Replies: 10
    Last Post: 03-19-2008, 01:56 AM
  4. Retrieve string(s) from (txt) file
    By Gordon in forum Windows Programming
    Replies: 12
    Last Post: 08-10-2007, 04:34 PM
  5. reading the nth item from a txt file
    By Opel_Corsa in forum C++ Programming
    Replies: 1
    Last Post: 11-18-2006, 05:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21