reading a .txt file help

hello,

I need to make a program that reads a .txt file and assigns the words to a string in one line.

For example in the .txt file i have something this:
Line 1
Line 2
Line 3

I want to assign it to a string so the string look like this:

Line 1 Line 2 Line 3

I know how to read the file using a loop
but I want so i can call this string anytime
, any help is appreciate
closed account (S6k9GNh0)
Pretty often, you'll get two things here.

1. You read the entire file and perform simple to complex parsing on the data received.

2. You'll read a file by sentence, generally ending with 0x0a (newline, '\n'), often placing each line in a string. This method is rather limited.

If you go with method one, just remove each newline and replace it with a space.
If you go with method two, then just read each line and insert the string into your resulting string.

I recommend method one. It's more straight forward and what you'll be using in almost all situations.
Or were you wanting code >.>
Last edited on
closed account (zb0S216C)
BruteCOder wrote:
I want to assign it to a string...

Well, it's quite straight forward. All you have to do is create a string instance. Then, extract each line from the file. Then, append the extracted line to the back of the string.

Wazzak
Last edited on
Topic archived. No new replies allowed.