Troy shows his solution to the challenge of writing strings to a text file.
(light music)…- [Instructor] Welcome back.…Hopefully you solved the challenge.…To solve this challenge, we need to use…our knowledge of path and ofstream.…We create the file using path,…and write to it using ofstream.…I also use a range-based for loop for the iteration.…Let me show you my solution.…But first, remember, there are lots…of ways to write a program.…Our solutions don't need to match.…So, of course, we have our include files.…
I am creating a name space using boost::filesystem,…and then I have my count to 10 function…and the very first thing that I'm going to do in there…is I'm creating a path variable and it's set to count.text.…That is the name of the file that it's going to create.…Then it's creating an output stream…and it's going to be called ofs,…and it's setting itself to what's…contained inside of the path.…And then I've got a range-based for loop here,…and it's just got the numbers one through 10 in there.…
And then for each line, it's going to say line number…of one, line number two, all the way up to 10,…
- Major new C++ features
- Turning on modern C++
- Letting the compiler help
- Using the new features correctly
- Using auto type deduction
- Using lambdas
- Range-based for loops
- How C++ and the Standard Template Library name things
- Making the best of the filesystem library
- Managing objects
Skill Level Beginner
1. What Is Modern C++?
2. Tools That Improve Your Code
3. Using the New Features Correctly
4. Don't Reinvent the Wheel
5. Managing Objects
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.