473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

loading from a file syntax question

I'm trying to load from a file i was just wondering if anyone can see if there are any syntax errors
P.S. my save part of the code works.
thanks in advance for help
Expand|Select|Wrap|Line Numbers
  1. ofstream myfile;
  2. ifstream load_file("Game save.txt");
  3. string line;
  4.  
  5. class BadConversion : public std::runtime_error {
  6. public:
  7.   BadConversion(const std::string& line)
  8.     : std::runtime_error(line)
  9.     { }
  10. };
  11.  
  12. inline double convertToDouble(const std::string& line)
  13. {
  14.   std::istringstream i(line);
  15.   double x;
  16.   if (!(i >> x))
  17.     throw BadConversion("convertToDouble(\"" + line + "\")");
  18.   return x;
  19.  
  20. if(load_file.is_open())
  21.                               {
  22.                                   while(! load_file.eof())
  23.                                   {
  24.                                       getline (load_file,line);
  25.                                       money = convertToDouble(line);
  26.                                       //cout<<"Here is your previous game winnings: ";
  27.                                       //cout << money << "\n";
  28.                                       //Sleep(3000);
  29.                                   }
  30.                                   load_file.close();
  31.                               }
  32.  
Nov 27 '07 #1
1 1356
oler1s
671 Expert 512MB
I'm trying to load from a file i was just wondering if anyone can see if there are any syntax errors
Generally, this is what a compiler does for you. We can check if there are overall incorrect code that wouldn’t be caught by a compiler.

Slightly odd, but it seems like you have statements outside of a function scope. Look at that part: if (load_file.is_open… ) . Is it within a function?

You’ve definitely misused EOF. Look at the while loop where you test EOF, and then use getline. Let’s see if you get the hint, and if not, I’ll explain further. eof() doesn’t check if the next read would hit an EOF. It checks if the EOF flag is set, which would only be set by a previous I/O operation. Now, why would a I/O operation set the EOF flag?
Nov 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Matthew | last post by:
I am not the most talented programmer to grace the earth by a long shot. But I've got a gripe I need to air about the .NET implementaion of Visual Basic. I can live with alot of the major changes...
4
by: Razzbar | last post by:
I need to be able to conditionally load a remote script, using the "<script src=..." syntax. Or some other way. I've seen people writing about using the document.write method, but it's not working...
5
by: floods | last post by:
I use Microsoft.XMLDOM load() method to load an XML file into memory and display some elements in the browser. However it apparently locks the file, since I get this error message whenever a...
5
by: Jay Douglas | last post by:
I have a set of pages that inherit from a base class in the App_Code folder. The class looks something like: public class MyBaseClass : System.Web.UI.Page In various stages of the life cycle I...
2
by: Dave A | last post by:
I just don't get this... If I need to dynamically load controls into a web page I simply need to go PlaceHolder1.Controls.Add(new Button()); or similar. However when I need to dynamically...
5
by: Cenk Genisol | last post by:
Hi NG, I am relatively new to Web developement and have some questions to you. I've got a Masterpage where some graphics are embedded by CSS. They format the borders of tables, which store...
1
by: FreeXenon | last post by:
OK, I am having a lot of problems loading an XML file via a Server-Side JavaScript based ASP page. Below is the code that I am using as well as the different methods of loading the XML file and the...
5
by: Pete Marsh | last post by:
Wondering if anyone can recomend some sample code for dynamically loading the GD module. I have tried setting the extension dir in php.ini, and loading the GD module from there when apache is...
3
by: Paddy | last post by:
Hi, I am am falling at the first hurdle when trying to access a library using ctypes. I have a file libucdb.so which the file command says is shared object, but I cannot get it to load: Any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.