wayneprim

Members
  • Content count

    13
  • Joined

  • Last visited

Community Reputation

148 Neutral

About wayneprim

  • Rank
    Member
  1. entering a string of data to an ofstream file

    never mind I got it with cin.ignore() thanks for the help!!
  2. entering a string of data to an ofstream file

    Thanks, but now when I change cin>> to getline() the program doesn't let me enter the data. Instead it just skips the data and jumps to your data has been entered successfully... Is there anyway to make the program "pause" to allow me to enter the data?
  3. entering a string of data to an ofstream file

    because when I use it in the main function, getline(cin, filedata), and then run the program i automatically skips that and doesn't let me enter anything.
  4. entering a string of data to an ofstream file

    do i use the getline on the function that is called or when I first get the input from the user?
  5. I am trying to create a program that allows the user to do 2 things (create a new file in the current directory, or search a file and display the word count) The word count works fine but when I try to allow the user to create a file it starts going wrong. I first ask the user to input a filename, and then enter some initial data into a string variable. That string variable gets passed to the createFile() function which takes care of entering the data into the file. When I run this program I enter the file data I wish to put in the created file, say for example " Hello File Data" and when I look into that file once its been created there is only the first word ("Hello") in the case of this example. Here is the code: The main function: [source lang="cpp"] cout << "Enter the file name: " << endl; cin >> filename; outFile.open(filename.c_str());//create the file if (!outFile) { //file could not be created cout<< "File could not be completed" << endl; break; } else // file was created cout << "FILE WAS COMPLETED NAMED: " << filename << endl;; //ask the user to put some data y/n cout << "Would you like to set some initial data in the file? y/n" << endl; cin >> choice; switch(choice) { case 'y': cout << "Enter the data: " << endl; cin >> filedata; user1.createFile(outFile, filedata); break; case 'n': cout << "Ok then dont create initial data... Your created file is blank" << endl; break; } [/source] The create filefunction: [source lang="cpp"] void User::createFile(ofstream &outfile, string filedata) { //output the file into outfile outfile << filedata; cout << "You have successfully saved the data you entered" << endl; } [/source] Please help! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Thanks I will attach the zip folder as well just in case...
  6. Why even use virtual functions in a Parent class?

    thanks for all the help, I got it now! lol
  7. Why even use virtual functions in a Parent class?

    This does help, thanks!! I just feel like making that virtual declaration in Automobile is so useless still, because if I wanted I could just erase it, and then in the main.cpp just call Ferrari auto("NAME"); auto.drivespeed(); maybe ill get it more when there are more complex functions but it just seems like a useless addition... lol sorry if I am not getting this... the answer is probably very simple and will be something like, "Ohhhh, wow I see it now.."
  8. Why even use virtual functions in a Parent class?

    hopefully this isn't so to everyone but in the second block of code it seems to be cut off... ill include it here: //implementation of classes void Automobile::drivespeed() { //does nothing cout << "UNDEFINED" << endl; } Ferrari::Ferrari(string name) :mName(name) { } void Ferrari::drivespeed() { //drives fast cout << "DRIVES REALLY FAST" << endl; }
  9. So I am learning about inheritence and currently I am on polymorphism... I got the whole inheriting functions from the parent class in order to not duplicate code however I am stuck on one thing: The virtual function... So say I have a class named Automobile like so with a child class that is named Ferrari: [source lang="cpp"] class Automobile { public: virtual void drivespeed(); }; class Ferrari: public Automobile { public: Ferrari(string name); void drivespeed(); private: string mName; }; [/source] [source lang="cpp"]//implementation of classes void Automobile::drivespeed() { //does nothing cout << "UNDEFINED" << endl; } Ferrari::Ferrari(string name) :mName(name) { } void Ferrari::drivespeed() { //drives fast cout << "DRIVES REALLY FAST" << endl; } [/source] now in the main.cpp file in the main function i could write like so... [source lang="cpp"] int main(int argc, char **argv) { Automobile *auto = new Ferrari("Spider"); //invoke drivespeed function auto->drivespeed(); return 0; } [/source] all this does is creates an object of the ferrari type (upcasting it to the automobile type) and then lets me invoke methods of that class... So here is my question: What difference does the virtual function declaration in the Automobile class make? Couldn't I skip the declaration in automobile function since it is really not even a function (it does nothing) and just declare the function as normal in the Ferrari class? and if i made more child classes of the parent class Automobile, i could do the same? Please let me know Thanks, Wayne Prim
  10. New career path

    Before answering this I want to tell you that I am not a complete expert... I have programmed for a couple of years and a year of that in C++, and have done some OpenGL but I have come across this problem many times and since no one has responded to you yet I feel that I will put in some of my own input, maybe it will help, maybe it won't. Also note that I am only recomending to learn c++. This is because I learned this way, and it is the industry standard for 3D games. There are many other languages obviously, but since I have little experience with them I feel I should leave them out for a more experienced person. I see that you have some experience in C++, or had experience. I think it is very important for your sake to start that over from the basics as you said it has been a few years since you were learning the language. There are great books out there (I will list them below), that will cover mostly everything you need to know and get you started on text based games, these are awesome (sometimes boring) ways to get to learn the language and how to use it making the structure of the game loop. There are different ways to go about these books, one being reading it diligently through just once, covering every exercise and not leaving any chapter until you are proficient leading you to the end of the book where you should know almost everything you can about the language, or at least to the extent of what the book teaches. This way of going about it is great and you will learn a lot but I feel that it is limiting in ways. When you read a text book and strictly follow its exercises you don't really allow yourself to explore other things, be creative and make mistakes. I think the best way to go about it is use the book as a sort of reference. Sure you can read the text from front to back doing this but the way I did it was I read a bit of knowledge, and created what I could from that knowledge... This made it a lot more fun and increased my learning curve. Just know, the book will stay around for much longer if you do it this way since you are taking some time to practice the material but I think it is very worth it! [b]Great books for C++:[/b] C++ Primer(4th edition) by Stanley B. Lippman is a great book. I learned from it and highly recommend it for others. C++ Programming Language by Bjarne Stroustrup. Great book, I delved into this a bit after the Primer. It is great to learn from the very inventer of the language [b]Great Web Tutorials:[/b] learncpp.com (awesome site, best and only web tutorial I recommend) After you learn the language I think you will have a good idea into what you want to learn next, whether it be the Graphics API, or maybe something more specialized like AI. But that is all I have for you, sorry if it is not enough! GL! Wayne Prim
  11. I have a question regarding the compilation of a simple c++ program. I just got a new computer and downloaded Microsoft Visual c++. I then created a Console application to test if everything is dandy. I made a simple hello world application with the precompiled stdafx.h files included and received this error: LINK: fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt it wouldn't let me even compile the program.... I looked into the web and found out one simple thing: 1. go into project | properties | Configuration Properties | Manifest Tool and then make sure Embed Manifest is turned to No instead of Yes. I did this and it worked perfectly... so my question is this: Why does my project compile now that this simple project property is changed? What does this do? Will I run into problems if I continue to leave it turned to No? Please let me know if you need any more information on this matter. Thanks in advance! Wayne Prim