How to open and close files in C++? fstream
HTML-код
- Опубликовано: 26 авг 2024
- You will learn how to close and open files and how to check if the file was opened properly. You also learn how to simply put text into a file.
You can learn more about C++ fstream library in my course:
www.udemy.com/...
#fstream #cppshorts #cpp
Wanna try my course and find out more about C++? 🙂
www.udemy.com/course/video-course-c-from-beginner-to-expert/?referralCode=F835B8AEE9C81FFE5BE5
If you have any questions regarding C++ feel free to ask!
I still can't get a file to open. Does it matter where you save it?
@@viratsharma8036 I just figured it out too (thanks to the other comment about maybe the file being in the wrong file) So you need to first create a txt file IN the project file (not the debug file, and also not outside - just find the file that has your c++ source and create the txt file there) Hope this helped others too (I've been nearly driven mad by this lol)
@@olivialai. 2 Years later you saved me!! Thank you so much
@@olivialai. 4 years later you saved me!! i was losing my mind over this
How cool is that we all have similar problems even tho so much time have passed :-)
Looks like my video has the power to time travel! Glad I could finally save the day!
polak
+1
Tak jest :)
How do i use C++ to actually open the text file into a new window?
What do you mean by a 'new window'?
@@VideoKursPLi want to use the c++ code to open the physical file. like in the note pad window.
@@Frazer213 have u done it? ://
@@Frazer213 how do you do it?
@@Frazer213 any updates????
But how do we read files with the c++?
This is free lecture, the rest is in the course :)
@@VideoKursPL all information should be free and publically available. Idc if it's in the course or not, if you know how to help you should. I don't so I can't
To read files in C++, you can use the ifstream class from the library.
std::ifstream file("example.txt"); // Replace with your file path
if (file.is_open()) {
std::string line;
while (getline(file, line)) {
std::cout
Psych I just figured it out.
I'm glad you did!
poska