Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » reading & writing a file
Re: reading & writing a file [message #32657 is a reply to message #32655] Tue, 31 May 2011 19:38 Go to previous messageGo to previous message
unknown user
Hello,

Please use [ CODE ] [ /CODE ] tags to mark code, so it get well formated.

Standard functions reside in std namespace so, you have to add
using namespace std;
after your includes
#include <iostream>
#include <string>
#include <fstream>
using namespace std;


In Readini you're missing an ')';
line:
file.getline(&(buf[0], 300);

You may write Readini like:
String Readini(ifstream &file)
{
	char buf[300]; // up to 300 bytes per line of input
	file.getline(buf, 300);
	return String(buf);
}


In DoLoadFunctions:
inline - is a C++ keyword, so you can't have a variable with that name;
break - it's a C++ keyword, not a function;
Correct DoLoadFunctions would be
int DoLoadFunctions()
{
	String file = "learn.ini";
	ifstream inifile(file);
	while (1)
	{
		String inl = Readini(inifile);
		if (inifile.eof() == true)
			break;
	}
	inifile.close();
	PromptOK("This is a test");
	return 0;
}


You may use U++ functions so you don't have to mix STL code with U++. If you want to read one byte at a time you may use use the following code:
FileIn fi;
fi.Open("learn.ini");
while (!fi.IsEof() && fi.IsOK())
	fi.Get(); // do something with it...


If you want to read an *.ini file you may use LoadIniFile (see help).

Andrei

[Updated on: Tue, 31 May 2011 19:40] by Moderator

Report message to a moderator

 
Read Message icon5.gif
Read Message
Read Message
Read Message
Read Message icon13.gif
Read Message
Read Message
Read Message
Read Message icon7.gif
Read Message
Previous Topic: GridCtrl out-of-bound crash with test case
Next Topic: using a file chooser (dir chooser??) to get a dir and not a file
Goto Forum:
  


Current Time: Mon Jul 07 13:51:02 CEST 2025

Total time taken to generate the page: 0.03854 seconds