Skip to main content
gamedev.net
🔒 Locked

fstream.h problems

Started by SonicD007 Jun 1, 2006 at 4:57 PM 6 replies 650+ views
Original Post
SonicD007
SonicD007
I'm currently still trying to get down a few things with c++, and IO is one of them. I have the tutorial found on game dev saved onto my computer so that i may study it, but I'm having errors when I use the fstream.h file. This is the error I get. I have only included no iostream. I'm trying to follow the tutorial that is on game dev. 2 C:\Dev-Cpp\include\c++\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated. I think there is something wrong with the fstream.h file itself. Please if anyone else is having or has had this problem, can you tell me what is wrong?
Enigma
Enigma
Which tutorial? It would appear that it is incorrect.
Quote:
Misquote from the film The Matrix
There is no

It's . You'll also probably have issues with namespaces. Might be time to find another tutorial, or head over to the For Beginners forum and check the stickies for the recently started C++ teaching (requires you to obtain a textbook).

Σnigma
SonicD007
SonicD007
http://www.gamedev.net/reference/articles/article1127.asp thats the tutorial.
Enigma
Enigma
Yeah, look like it's based on pre-standard C++ (over eight years old). Best advice is to skip it and find another tutorial.

Σnigma
SonicD007
SonicD007
Ah thanks. I have good news though. My friend looked at the code and just added the iostream file to it and using namespace std; and it works now. Still not sure what was screwing up but I think including the iostream file fixed it.

Thanks for the response.

=) (I can't wait to get started using files!! ^.^)
SonicD007
SonicD007
I got IO working in my program, but when I try to store strings into a file, if they contain spaces, it only stores the first word. I know about getline when your reading a file. The user is inputting a string into a variable. The variable will then be written to the outside file. But when there are spaces, the sentence is not put in there because there are spaces. What can I do to fix this?
Oluseyi
Oluseyi
Quote:
Original post by SonicD007
I got IO working in my program, but when I try to store strings into a file, if they contain spaces, it only stores the first word. I know about getline when your reading a file. The user is inputting a string into a variable. The variable will then be written to the outside file. But when there are spaces, the sentence is not put in there because there are spaces. What can I do to fix this?

There are two functions named getline, and they do very different things. Sort of.

std::istream::getline is a member of istream, as the name indicates, and reads data into a character array. std::getline is a member of the std namespace, and reads data into a std::string. std::getline is cleaner and easier to use:
#include <iostream>#include <string>int main(){  using namespace std;  string line;  cout << "Enter a line of text. Feel free to include spaces, and don't worry about length\n> ";  getline(cin, line);  cout << "The text you entered appears below:\n\n" << line << endl;  return 0;}

Use std::getline and std::string. Because std::ifstream derives from std::istream, std::getline can be used on ifstream instances, too - you can use it to read from files.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.