Pulling text from a txt file to a c string.

F

foenotes

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
 
V

Victor Bazarov

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
 
R

Ransome

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top