| Stauricus (10) | |||
|
hello i have a little question here. i have read the tutorial, but didn't quite understood how to work with input/output to/from files. let's suppose i have a file, called file.txt:
and i create an array in the main(): string mArray[5];how can i make each one of the array members get one of the words? i mean, how to tell the program "from here to here will be mArray[0], so mArray[0] = "word1". from here to here will be mArray[1], so mArray[1] = "word2", etc"? i think a 'for' loop would do fine. i just need help to take a serie of characters from the .txt file and convert it to a string. i have no idea on how to do that... thanks in advance! :) EDIT: i tought about putting a specific character between the words i want, so the program can separate them. is this possible? | |||
|
Last edited on
|
|||
| Dash (122) | |||
You don't need commas between words, remove the commas and this will work fine (be sure to leave spaces between words):
| |||
|
Last edited on
|
|||
| Stauricus (10) | |
|
really that simple? wow thanks for the quick answer. another question, then. is there any way to make a string hold more than a single word? example: mArray[0] = "word1 word2"; and then, make the same as above, but with these "sentence" strings? thanks again! | |
|
|
|
| Stauricus (10) | ||||
|
hi everybody! sorry for the double post. after a bigger search, i found out how to do this, and just wanted to share the solution, in case anyone wants to do the same thing. how i did it: i store the whole contents of the .txt file in a single string, close the file, and then, split the string, based on searching a specific character: a | bar. text file test.txt: helloooooooooo|cool cool|another string|laaaaast one|the bar "|" is needed to separate words/sentences. and main.cpp:
EDIT: and the output:
| ||||
|
Last edited on
|
||||