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
@cmommsen113 жыл бұрын
@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.
@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
@Qazqi12 жыл бұрын
Not sure why you'd prefer character arrays over std::string. Anyway, just read it with while (std::cin >> word) {std::cout
@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.
@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.
@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
@FastCodeDeveloper9 жыл бұрын
man you must be the most subscribed programmer-youtuber of all time...
@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
@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.)
@sum21chan15 жыл бұрын
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!
@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);
@Finalfox0910 жыл бұрын
Thank you this tutorial was a life savior
@concernedviewer69094 жыл бұрын
Just wanna say again, Welcome back Buckey!!!
@CensSka8 жыл бұрын
I've got an exam tommorow I'm screwed
@thinumstoneheart67138 жыл бұрын
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
@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.
@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.
@arraybabe851412 жыл бұрын
yes, use getline and dont forget to include the string header
@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
@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.
@jasperko3085 жыл бұрын
Solution for programs that couldn't work. You need to select file on the top left hand corner in CODEBLOCK
@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)
@MozartTime12 жыл бұрын
I just needed to refresh my mind about fstream. Loved this , so clear as good.
@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.
@muhammadbinsaleem85654 жыл бұрын
Bro ! May you live happy life...
@Wingedzephir13 жыл бұрын
Great you just solved all my problems with this simple example...well done thanks!
@fernandinhoflor13 жыл бұрын
Add in the end of while the following expression: if(!bucky.good()) { bucky >> word; cout
@r3sp3c79114 жыл бұрын
Couldn't get a think from this one, it was so fast!!!
@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 ?
@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
@usabnd14 жыл бұрын
@linglihe ofstream is for output file. it means if you want to change the content of a file.. hope I helped
@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?
@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.
@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
@Mrlpjo13 жыл бұрын
i understood after watching the third time... not so confusing as i thought at first..
@dumacele67243 жыл бұрын
so relatable "come on baby",,,exctly how we al talk to our computers when we're in the zone
@GregVanGorp12 жыл бұрын
instead of using exit(EXIT_FAILURE); it would be easier to explain "return 1;". For all of you beginning programmers, this returns a value to int main() and signifies that the program did not execute correctly. Both methods work, but for beginning programmers, this is simpler.
@genjimidou13 жыл бұрын
After seeing 5 times I finally understand ...xD
@kotapaka12 жыл бұрын
Oh...OK. I merely thought of pointing out that learning/knowing C++ and the standard library is probably the easiest step in the world of programming and software (especially reading/writing files). In C++ read/write file operations are made a breeze by the library.
@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.
@meyerflyer3412 жыл бұрын
It could be used for storing options in video games and then outputing them with a custom GUI.
@sumittechkgp13 жыл бұрын
if you are using EXIT_FAILURE then use return(EXIT_SUCCESS) instead of return 0
@HarisMalik6 жыл бұрын
instead of adding cstdlib we can use same code but exit(0) and the program must exit
@CloakLord10 жыл бұрын
I am working on a planner I've got it to read the class end line , homework end line , and then the day its due on to the file and read it from the file. Although, I have 4 classes and I don't know how to name the variables in a way where I can have it restate all the homework correctly. I have tried multiple ways and many dead end ideas such as call functions which seemed genius at the time to read it from the file and based on which it is to have the variable be set to that in that call function. I just had an idea to have it read from multiple files based on the class, but seems impractical.
@CloakLord10 жыл бұрын
This video helped a lot o.o
@PaxiKaksi6 жыл бұрын
But getline eats the last word in your text so........ That is a bit inefficient ?
@Ishakislife15 жыл бұрын
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!)
@andreipopescu8714 жыл бұрын
to repaire the problem with not showing the last word from bucky's tutorial just delete bucky >> word; from above the while loop and reverse the 2 lines inside de while loop { bucky >> word; cout
@muhammadfariezdaniel47693 жыл бұрын
wah thankyouuu>< I am watching this in 2021
@2testtest215 жыл бұрын
you need a compiler to make you code into a executable. If you wathc thenewboston's C++ tutorial.
@th3kid1314 жыл бұрын
hella good tutorial keep it up!
@reggaemediatv11 жыл бұрын
Thank you
@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?
@yougurtbeautiful98955 жыл бұрын
Write a function in C++ to write the characters entered through the keyboard into the file“ myfile.txt”, until a '#' character is entered.
@Mozi11111114 жыл бұрын
It works great! Thank you!
@mokab22312 жыл бұрын
THANKS BRO!! great job !!
@kottpower13 жыл бұрын
This is the most difficult tutorial yet.
@SimpleCookiee12 жыл бұрын
First time I watched it i thought it was difficult then I took a break, had dinner and thought about t for a while.. Then alll cleared up. I found it a bit confusing you didn't have to specify to C++ that you want the next word.. It actually takes it automatically cuz you did the ~~~ = word.
@DRDSkidroW13 жыл бұрын
@SuperiorOnRoblox make sure you placed the exclamation mark in: " if (!test.is_open()){ " that was my problem
@ChadDrakeTech8 жыл бұрын
Your videos started off well bu now you just rush through everything.
@establishment41328 жыл бұрын
K then pay more attention
@kaushikdr5 жыл бұрын
@@establishment4132 it is kind of fast though
@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?
@josephrowell90525 жыл бұрын
When I do this, whatever actual file there is, it prints loads of zeros?
@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
@Vlaxiti15 жыл бұрын
nice and clear !! thnx
@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....
@chris7toronto12 жыл бұрын
Thanks Bucky!
@EjMacarus5 жыл бұрын
"and if you don't believe me..."
@baarbie07869 жыл бұрын
So what is the ideal way of reading from a file?
@awesaatyanta31066 жыл бұрын
couldn't you just use like if (!bucky.good()){ return 0; } instead of including another library? it works for me so is there any particular for using the cstdlib for exitting my program ONLY or is it just matter of preferences?
@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) ?!?
@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
@TheMohawkNinja14 жыл бұрын
@linglihe I think that of is Output File, and if is Input File
@tarBall31315 жыл бұрын
i'm sorry but i don't understand the word 'getto'. But if it's a bad word (like shit, bad etc.), that's not what I meant. Simply visual studio has extended functionality and 'auto-coding-style' (it arranges the lines according to braces etc.)
@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 :(
@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!
@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?
@stephenreader59539 жыл бұрын
Thank you!
@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??
@sabrinazeb13 жыл бұрын
Thanku so much awesome tutorials.. :D
@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?
@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?
@yoloop9315 жыл бұрын
mine doesn't open as text file but opens with cmd.help!
@insomeperson11 жыл бұрын
Why does it always ignore the last word?
@GNSstudios15 жыл бұрын
you showed how to write a file but what if i wanted to write the file to a specific directory.
@Milo_110512 жыл бұрын
Or you can put main as a void and do not worry about returns.
@netherar11 жыл бұрын
great tutorial! ty
@dyrokudobane10 жыл бұрын
I see the program terminated once it reached the end-of-file, so the c++ part didn't print out. Probably wanna take the word from the back file then print it out right after within the while good loop ( omitting the bucky >> word line). Regardless, not bad.
@NubPaws10 жыл бұрын
Or... He could have stored the file in a string variable using the cin.getLine(strVarName); I would assume that would be simpler.
@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.
@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?
@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.
@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... !
@zeen51637 жыл бұрын
does "bucky >> word" get the word from the user and stores it in the file? or what does that actually do?
@IvanRubinson15 жыл бұрын
I want to make my program read the first line and execute it (For example, if in the file it says Cout
@pranoydutta54358 жыл бұрын
instead of including the cstdlib to use exit, can we just return 124721; as this is in main
@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
@RaamAnkka14 жыл бұрын
wait guys only thing dont understand is that what is "word" used for... is that a variable he made up???
@davidalyakobi68577 жыл бұрын
Hey Bucky why did you use exit(EXIT_FAILURE) instead of exit(1) ?
@Mrlpjo13 жыл бұрын
@TheResponsae. Is that really needed??? I think the file automatically closes once the execution is over?!
@ivaka9213 жыл бұрын
while i was watching this tutorial i sat back in my chair, adjusted my glasses and said to myself "shit just got real"....
@WikiPeoples14 жыл бұрын
how come it didnt read the entire line? It left out "C++!" .... mines doing the same thing