C++ Programming Tutorial 60 - Writing to Files with ofstream

preview_player
Показать описание


~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

🅑 Bitcoin - 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq
🅔 Eth - 0x350139af84b60d075a3a0379716040b63f6D3853
Рекомендации по теме
Комментарии
Автор

I like how in a lot of your videos you say something like "This is a bit difficult to explain but I will try my best", and then go on to do a perfect explanation of the particular subject and make it a super easy to understand.

chriscruz
Автор

Every time I hear "our sponsor" its put a big smile on my face, coz it's too CUTE!

alexplaytop
Автор

For Windows, right-click the file and select “Properties”. Then check the “Read-Only” box.

sirskylight
Автор

Caleb, any chance you are down to make like a advanced version or intermidiate version of this series so when we done we can learn even more.

YTBCLIPS
Автор

Hopefully in the future Caleb you will do the Visual Studio version for this as I don’t know how to use Visual Studio Code.

brownshirt
Автор

This video is shockingly simple and well spoken!

Ryan-xqkl
Автор

Ofstream? More like off the chain, because this tutorial is unbelievably amazing!

PunmasterSTP
Автор

that's my 20 for the day. 2 more days and I'll have gone through them all. If we're not friends by the end of this journey.. I'll be sad

guitarhax
Автор

its a marvellous series for me and all thanks to my favourite sir caleb curry

stevewilliams
Автор

If anyone is getting an error that reads, "Vector is not a member of std", you'll need to add #include <vector> to your std list above. (ex. #include <iostream> #include <fstream>).


I'm using CodeBlocks. Let me know if this helps anyone!

itsMKiAM
Автор

For some reason, I needed to use std::fstream::out to create the file, at least for the first time.

tnkspecjvive
Автор

Question, just to clear up what would std:: ofstream outFile mean?

yasminmontesino
Автор

If you're using visual studio 2019, you can do this:
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ofstream writer("file.txt");
if (writer.is_open())
{
int birds = 4;
writer << "Someone one told me the world is gonna know me." << endl;
writer << "Shrek 2020 wtf" << endl;
writer << "There are: " << birds << " birds" << endl;
cout << "Writing was success!" << endl;
}
else
{
cout << "Error!" << endl;
}


writer.close();
system("pause");



return 0;
} //Thats to write in the file.


The second is for ifstream, basically it reads the string or int in the file. You also need to make a new text document in that project like I did with file3. You can do that by right clicking on your mouse. Click new then click on "Text Document" then rename the file to whatever its reading it from. Now in that file you could put numbers 10 and 20. Close the file then compile the program and it would give you Sum of variables a and b is: 30.
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream reader("file3.txt");
int a, b;
if (reader.is_open())
{
reader >> a >> b;

cout << "Sum of variables a and b is: " << a + b << endl;

}
else
{
cout << "Error." << endl;
}


reader.close();
system("pause");



return 0;
}

thejokercrypto
Автор

I have a question why is c_str() used with in 9:04 is it important or can we not use it

o.
Автор

if I wanted to make a file in a specific folder, like the desktop, how would i go around that?

jaakob
Автор

hello that is awesome i am learning to code and c++ is my base language i ve choosen. How can do like this and encode and decode what i am storing in the file.txt? please i am learning so i really dont know how to do that :) thx

ksp
Автор

how do you write to a specific line? thank you.

uzzielledelacruz
Автор

I am trying to do this and getting a "'file' was not declared in this scope; did you mean fileno" message, is anyone else getting this, if so, any idea what the fix would be?

ryanbodily
Автор

i need to take the output of a void function and write it to a file, except I can't find ANYONE who explains what else you can write to a text file other than simple strings.

bodeabbott
Автор

Great Tut.
Only fault is LIGHT THEME !!!! 😫

Icy_Republic