@rockydasha Re:Basically, bucky is a variable of type ifstream, due to this statement: ifstream bucky; And after this statement: bucky.open(filename); bucky is now "connected" to the user-defined file name contained in filename - in this tutorial, "beefy.txt". Therefore, when you use it with >> (known as the extraction operator), the stream looks in beefy.txt, finds the letters 't', 'h', 'i', and 's', and "streams" them into word. The next letter is a space, so the stream operator terminates.
@InSpmindss14 жыл бұрын
you are the best teacher i ever have seen in my life, in real sense ,you teach in the best way , a lot lot more thanks to you for providing such materials
@CensSka8 жыл бұрын
I've got an exam tommorow I'm screwed
@thinumstoneheart67137 жыл бұрын
LMAO same af man
@informativecontent47787 жыл бұрын
mine is tommorrow wish me luck
@jimmychan92826 жыл бұрын
mine is tomorrow
@ZainiverseCreations6 жыл бұрын
Mine is tomorrow LOL .. Everyone comes to bucky a day before exam ...
@Mustafalllica6 жыл бұрын
mine is tomorrow
@zarigull2745 жыл бұрын
This link is best to learn programming because before this i had no idea about file handling but know i can describe this frequently thanks
@colinrickels20111 жыл бұрын
i have gone to hell and back looking for a tutorial such as this thank you so much
@Haris0423lhr4 жыл бұрын
you look like jesus so no problem for you
@johnnyc13015 жыл бұрын
Great tutorials. You are very clear in all of them and dont leave me confused like some other tutorials. I made a program that can open files, and create files to write on.
@Finalfox0910 жыл бұрын
Thank you this tutorial was a life savior
@jgray11012 жыл бұрын
Thanks Bucky, finally got a file to read after dozens of other search code attempts because I was afraid I couldn't do this, but I tried it and walla, don't forget to bucky.close after while { }. system{"pause") is operating system dependent so eventually we need to learn OS independent code. These tutorials get an A++
@rybread57186 жыл бұрын
Thank you my good man. I used #include and it worked the same.
@christophergaspar65203 жыл бұрын
anybody who sees this please help, i wrote a code similar to this in my visual studio I then noticed that, when the program is displaying the text file, the last word is not included. even in bucky's program, notice at 6:05 the last word ('C++') is not included. is there a way to fix this I would greatly appreciate your help, thank you
@Qazqi12 жыл бұрын
Not sure why you'd prefer character arrays over std::string. Anyway, just read it with while (std::cin >> word) {std::cout
@concernedviewer69094 жыл бұрын
Just wanna say again, Welcome back Buckey!!!
@OnlineMediaCollection7 жыл бұрын
Just needed this line, *while (iMyFile.good())* LOL. Thanks!
@thetruereality25 жыл бұрын
That wouldn't print anything, it would only work in case of an eof function. I think you meant while(MyFile.good)
@naimcool364 жыл бұрын
@@thetruereality2 hes right "good" is a function
@RazRikimaru12210 жыл бұрын
Hey is there any possible way to make the number from each line in the text file output into an array grid of variables ?
@usabnd14 жыл бұрын
@linglihe ofstream is for output file. it means if you want to change the content of a file.. hope I helped
@yomguioim9 жыл бұрын
you can get an open file box with tiny file dialogs on sourceforge is a single C C++ cross-platform file offering many native dialogs.
@Boeing737Channel13 жыл бұрын
@Yikak4 cin.getline = just like cin >>, just can manipulate it more. It gets the line you enter. (filename,50) is to store what you inputed in filename, and you need to include 50, the char character size.
@keykeyine12 жыл бұрын
Just as a side note, the way you set this up it's never going to print off the last word in the text file you read in. Not a big deal but I thought it might confuse some people. You just need another cout
@FastCodeDeveloper9 жыл бұрын
man you must be the most subscribed programmer-youtuber of all time...
@reggaemediatv11 жыл бұрын
Thank you
@octav3k13 жыл бұрын
@Duodecillian 50 is the maximum number of characters that variable can hold. So if you had a filename or word (the variables he defined inside the program) that's longer then 50 characters, only the first 50 would be read by the program.
@MozartTime12 жыл бұрын
I just needed to refresh my mind about fstream. Loved this , so clear as good.
@Wingedzephir12 жыл бұрын
Great you just solved all my problems with this simple example...well done thanks!
@Jonko19214 жыл бұрын
good for beginners. only a few tips to improve this program: change system("pause"); to cin.get(); and why using cstdlib? the stuff is already in the iostream library. the best thing to do is put the load stuff into a function and inside the function you put a return statement if the file is not open. dont use exit(exit_failure);
@PaxiKaksi6 жыл бұрын
But getline eats the last word in your text so........ That is a bit inefficient ?
@h8errage13 жыл бұрын
@shebotnov ofstream enters stuff into a file, and ifstream gets stuff from a file(read a file) i think u can use an fstream object that does both so u never have to ask yourself that question.
@bwneyeschik15 жыл бұрын
Do you do this often? If you do I may continue with programming. Otherwise, I think I may change my Major!! (this online class thing sucks!)
@sum21chan14 жыл бұрын
I like ur video!! just wanna remind you, you could press the tab button for go in 5 space (I think) instead of pressing the space 5 times!
@arraybabe851412 жыл бұрын
yes, use getline and dont forget to include the string header
@helpfullprogrammer15 жыл бұрын
how do you output the whole con-tense of the file? I can only get one word. thanks in advanced! from helpfullprogrammer.
@Digiscat13 жыл бұрын
If you ARE confused, just think a bit and mess around with the code. It'll help you both understand and remember. If you're like me, cin.getline and the array threw you off. cin.getline is like a more flexible cin >>---- So, in other words, its like he put "cin >> filename[50]"....get it? And if you make the number for the array smaller, that just limit how many characters it can hold. So, -- char file[50] -- can hold up to 51...but if you put file[1], itll only USE 2. (+1 since 0 counts.)
@r3sp3c79114 жыл бұрын
Couldn't get a think from this one, it was so fast!!!
@muhammadbinsaleem85654 жыл бұрын
Bro ! May you live happy life...
@razeal11312 жыл бұрын
its saying that the char string can be up to 50 characters long. ie, he doesn't know the length of the filename ahead of time so he allows for up size 50. if he was worried about extensions (blah/blah2/.../file) might have made it larger, but 50 should do for any file
@Mrlpjo13 жыл бұрын
@TheResponsae. Is that really needed??? I think the file automatically closes once the execution is over?!
@GNSstudios15 жыл бұрын
you showed how to write a file but what if i wanted to write the file to a specific directory.
@josephrowell90524 жыл бұрын
When I do this, whatever actual file there is, it prints loads of zeros?
@Mowteng14 жыл бұрын
i dont understand how you can go through each loop, where in the code you told C++ that you want the file content separated by space? why is the first cout in the while not the complete content of the file (with a max of 10 chars ofc) ?!?
@yasirwisal80819 жыл бұрын
Hi Bucky, How do you end line if there is a large text file with the string data type and do some calculation from data which is in text file?
@reggaemediatv11 жыл бұрын
what part of it dont work?
@octav3k13 жыл бұрын
@Silvertide82 You can create a file with Notepad (he did so before running the tutorial) inside the directory where he saved his cpp file. For example, if he had "tutorial.cpp" inside "C:\Users\Greg\C Toturials\", the text file would have to be in the same directory: "C:\Users\Greg\C Tutorials\beefy.txt". I hope that clears it up for you.
@mynewlife21011 жыл бұрын
Where should the file be located??
@HarisMalik6 жыл бұрын
instead of adding cstdlib we can use same code but exit(0) and the program must exit
@insomeperson11 жыл бұрын
Why does it always ignore the last word?
@octav3k13 жыл бұрын
Tou can't see the last word because the condition on the while function is put before the body of the function (he used while, not do-while) and each time the program reads a word with "bucky >> word", it moves to the end of that word. After it reads the last word, the function "bucky.good()" becomes false and it doesn't enter the loop again in order to post the variable (word) to the screen. He could have avoided this either by using do-while or through the method described by andreipopescu87.
@TheHeadmanmr12 жыл бұрын
What is this used for?? Would be much easier for my brain if I knew how this would be used in a real situation... !
@euktalinoo13 жыл бұрын
i want to read an array and i want to covent a string in to an integer.can you help me please?
@genjimidou13 жыл бұрын
After seeing 5 times I finally understand ...xD
@Lightscribe22513 жыл бұрын
Say I wanted to take a list of random numbers from a file, and find their sum and average. How do I go about doing that? Do you have a tutorial going over that somewhere?
@chuserio212 жыл бұрын
hey can u explain, why the 50 on the char file name? what it represents
@stereojos8614 жыл бұрын
you save the txt doc in the same folder that the program? My program dont read the txt, go directly to exit(EXIT_FAILURE); I copy and paste your program.
@dumacele67243 жыл бұрын
so relatable "come on baby",,,exctly how we al talk to our computers when we're in the zone
@LPSlasher14 жыл бұрын
3:30, People: keep in mind that using SPACEBAR in an empty line may wreck the code sometimes, don't try it. (in empty lines you should use either TAB or ENTER... Of course you CAN use SPACEBAR after a codeline)
@adeepnair10 жыл бұрын
how do i do this with a text file with numbers in it?
@TheSheniceJ9 жыл бұрын
+Adeep Nair ik its like a year u posted this but same thing i wanna know :(
@TheHeba6613 жыл бұрын
how can I create a file in the same directory? where exactly should I save it?
@Humbertorgr12 жыл бұрын
Ok it worked for me... But I made a txt file with two lines and is only showing up one :s... is there a way to use it with string instead of char?
@m4unot13 жыл бұрын
Can you open a "makefile" and use command: "make flash" to run it?
@baarbie07869 жыл бұрын
So what is the ideal way of reading from a file?
@WikiPeoples14 жыл бұрын
how come it didnt read the entire line? It left out "C++!" .... mines doing the same thing
@SimpleCookiee12 жыл бұрын
I wonder one thing tho... Let's say I recieve a input as value into a char[50].. Assume it got the value "people".. Now here's my question.. How do I add text to that variable? I want to add ".txt" at the end so I becomes "people.txt", how to do that?
@chernobila15 жыл бұрын
hello sir are you going to post more C++ tutorials? Please do Thank you
@anikatahir61463 жыл бұрын
Im having this problem that i have to construct a program to read my file where i have to provide choice for the user to select. Like i saved names and roll numbers in my file and now i have to provide option to user to select which roll number's name should be displayed/read....
@shekhardk12 жыл бұрын
Well this code doesn't read and print the last word in the file. If the file has just one word then it won't print anything.
@ivaka9212 жыл бұрын
20 y.o. here :) it was an honest reaction really - stuff until here was easy to comprehend and suddenly lots of commands and info! When i watched it 2-3 more times i got the hang of it... almost :)
@shidono67865 жыл бұрын
are you working now?
@IvanRubinson15 жыл бұрын
how do i made it so i decide wich file to open (as a programmer)... I mean pre-define that filename = [something]
@tarBall31315 жыл бұрын
Why don't you use Visual Studio?:)
@meyerflyer3412 жыл бұрын
It could be used for storing options in video games and then outputing them with a custom GUI.
@sarahbiebah6 жыл бұрын
Why doesn't line 6 CREATE the file like we have done before? How come this time it needs the file already created? What's different?
@MrBrightSide62214 жыл бұрын
ugh. Do you need to be admin like the last one?
@DRDSkidroW13 жыл бұрын
@SuperiorOnRoblox make sure you placed the exclamation mark in: " if (!test.is_open()){ " that was my problem
@Yizak13 жыл бұрын
What is cin.getline(filename, 50) ?
@muhammadmohaiminulislam71897 жыл бұрын
Can i write or read a character in a file at a selected position?Like adding 'a' at 2nd line , third position at file? Or read from a selected position?
@blacksven114 жыл бұрын
What is the [50] for???
@doerparol11 жыл бұрын
How can I make the program to store single characters instead of words? Afterwards I would like to process that stored information and count each letter so number of a= 50 b = 46 and so on
@davidalyakobi68577 жыл бұрын
Hey Bucky why did you use exit(EXIT_FAILURE) instead of exit(1) ?
@m4unot15 жыл бұрын
why do you say: char filename[50]; why 50 ? do you limit char with?? so if i say 5 .. i can only type 5 char??
@SuperFireEagle3 жыл бұрын
how would you code it to where it can automatically detect the input file name without hardcoding the name of the file into the program?
@yoloop9315 жыл бұрын
mine doesn't open as text file but opens with cmd.help!
@muhammadfariezdaniel47693 жыл бұрын
wah thankyouuu>< I am watching this in 2021
@chaouchsamir36357 жыл бұрын
what do you mean by using [ 50 ] ?
@dkblade2711 жыл бұрын
I thought when we open a file that we don't have, C++ will create it for us. So how come tunafeesh.txt didn't open??
@TheMohawkNinja14 жыл бұрын
@linglihe I think that of is Output File, and if is Input File
@zeen51637 жыл бұрын
does "bucky >> word" get the word from the user and stores it in the file? or what does that actually do?
@durraiz_ahmad188 жыл бұрын
Can you tell how can I skip/ignore line or row while reading a csv file and storing it in a 2d array?
@oumie935 жыл бұрын
Please help: do you know how can I input a ply file via C++ language ....?????
@TheAl2kas9 жыл бұрын
Hey, thanks for a useful tutorial, but I have a little problem. Program won't print last word. How do I fix it? :l
@Pcatalin669 жыл бұрын
+Aldis Petrauskas That is because the text is in that "char word[50]" and word[50] have only 50 slots. If you enter an text longer that 50 caracters (space included) than your program will cut the rest and stop at the 50 caracter. :D make sure that you give more than [50] ... maybe word[100] will help you .
@RexGalilae9 жыл бұрын
+Aldis Petrauskas The reason is because he types *bucky>>word* before *cout
@RexGalilae9 жыл бұрын
Lily Rathbun You first open the file and give it an alias (i.e. a placeholder) name, in this case, bucky. If you opened the file as , say "Lily", then you simply swap out all the "bucky"s from the code with "Lily"s. Pls. tell me if I misunderstood your question. I think I have misunderstood it.
@RexGalilae9 жыл бұрын
Lily Rathbun If you're talking about the location of the file in the directory, then it's automatically created in the same folder as your program.
@15sunny18 жыл бұрын
+Mohammed Zaid Thank you!
@AndToeKnee111 жыл бұрын
what if you want to copy codes from a website and paste it back like the ones to prove your not a computer ? lol
@pranoydutta54358 жыл бұрын
instead of including the cstdlib to use exit, can we just return 124721; as this is in main
@Milo_110512 жыл бұрын
Is "People" a class?
@leoking93811 жыл бұрын
Why is filename a char insted of a string?
@moazelsawaf20005 жыл бұрын
F
@nilufargh10 жыл бұрын
why did you use "of stream" in the other video for writing a file ?
@randohinn669110 жыл бұрын
o -output i -input
@nilufargh10 жыл бұрын
***** Thanks, if you don't mind, I just have a question about reading a data from a file and store it in a matrix. We have some data in a file that shows the amount of precipitation in specific time (like month and day). So our Prof built a matrix by getting the # rows and columns from the file. Then He set all the elements in that matrix= 0???!!!! ( In vectors and matrices isn't it like not having a value means zero so why do we have to set zero again?!) . Anyways and then in order to put those numbers into the matrix he said m.at(rows-1).at(columns-1)= num, we read the num from the file with rows and columns but why rows-1 and columns-1????
@randohinn669110 жыл бұрын
matrixes and vectors are 0 indexed so, the first element actually is at position 0 in the vector and so forth
@nilufargh10 жыл бұрын
***** True, but when you resize a matrix. let's say typedef vector< vector< int> > matrix; matrix m; m.resize(rows); for ( int i= 0; i< m.size(); i++) { m.at(i).resize(column); }// So now we built out matrix which is empty that means now all the elements are zero, right? we don't have to set all the values=0 again, it's not like arrays that elements are Not Defined unless we put a value in it. Right?
@leezhijiang10 жыл бұрын
What if that is an integer value ?
@hexmedi13 жыл бұрын
@HamishWare when you don't specify the directory, it searches for the given file inside of your project folder. at least this is how it works for me
@Mrlpjo13 жыл бұрын
i understood after watching the third time... not so confusing as i thought at first..
@abdulz115 жыл бұрын
hm... my file do not open ???
@fernandinhoflor13 жыл бұрын
Add in the end of while the following expression: if(!bucky.good()) { bucky >> word; cout
@Johnlolmann6 жыл бұрын
why do it open the file in cmd and not in notepad
@JosePimenta_JP10 жыл бұрын
hi, how do i read a code from a file? like instead of just opening a file and read the text. i want to open the file and read code that is inside that file. how it is done? thanks in advance
@josephchotard8 жыл бұрын
I know it's been a year but it would actually be impossible unless you implemented a compiler into your script to compile the code as C++ must be precompiled. If you really want to do this you should use Python
@kurekvision15 жыл бұрын
why do you make some programs in console by using c++ (very hard way) if you can do the same stuff with just few lines in notepad (batch file) and its very easy. I dont get you guys.
@Niffisa14 жыл бұрын
There is a problem with this program. It wont output the last word in your .txt file ;-)