Home » Community » Newbie corner » reading & writing a file
reading & writing a file [message #32655] |
Tue, 31 May 2011 17:47 |
silverx
Messages: 62 Registered: March 2011
|
Member |
|
|
I am trying to read a file, once I get that done, I will want to be able to write a file out. Not only read/write a full line at one time, but will want to be able to read/write a binary file 1 byte at a time.
Are their any examples of reading a file, and writing a file?
It doesn't seem to find ifstream.
Any help with this, maybe other includes?
The errors are as follows:
C:\MyApps\readme\main.cpp(13) : error C2065: 'ifstream' : undeclared identifier
C:\MyApps\readme\main.cpp(13) : error C2065: 'file' : undeclared identifier
C:\MyApps\readme\main.cpp(14) : error C2448: 'Readini' : function-style initializer appears to be a function definition
C:\MyApps\readme\main.cpp(24) : error C2065: 'ifstream' : undeclared identifier
C:\MyApps\readme\main.cpp(24) : error C2146: syntax error : missing ';' before identifier 'inifile'
C:\MyApps\readme\main.cpp(24) : error C3861: 'inifile': identifier not found
C:\MyApps\readme\main.cpp(27) : error C2513: 'Upp::String' : no variable declared before '='
C:\MyApps\readme\main.cpp(27) : error C2065: 'inifile' : undeclared identifier
C:\MyApps\readme\main.cpp(28) : error C2065: 'inifile' : undeclared identifier
C:\MyApps\readme\main.cpp(28) : error C2228: left of '.eof' must have class/struct/union
type is ''unknown-type''
C:\MyApps\readme\main.cpp(27) : error C3861: 'Readini': identifier not found
C:\MyApps\readme\main.cpp(29) : error C2143: syntax error : missing ';' before '('
C:\MyApps\readme\main.cpp(29) : error C2059: syntax error : ')'
C:\MyApps\readme\main.cpp(32) : error C2065: 'inifile' : undeclared identifier
C:\MyApps\readme\main.cpp(32) : error C2228: left of '.close' must have class/struct/union
type is ''unknown-type''
readme: 1 file(s) built in (0:02.05), 2059 msecs / file, duration = 2106 msecs, parallelization 0%
There were errors. (0:02.79)
The code is as follows, right now just a blank layout, is all I have. The code I got from a C++ book so I just copied what they had for it:
#include "readme.h"
using namespace Upp;
#include <iostream>
#include <string>
#include <fstream>
String Readini(ifstream &file)
{
char buf[300]; // up to 300 bytes per line of input
file.getline(&(buf[0], 300);
return String(buf);
}
int DoLoadFunctions()
{
String file = "learn.ini";
ifstream inifile(file);
while (1)
{
String inline = Readini(inifile);
if (inifile.eof() == true)
break();
}
inifile.close();
PromptOK("This is a test");
return 0;
}
readme::readme()
{
// added to make window sizeable and zoomable
TopWindow::Sizeable(true);
TopWindow::Zoomable(true);
CtrlLayout(*this, "Read a File on Start up");
}
GUI_APP_MAIN
{
int lfreturn = DoLoadFunctions();
if (lfreturn == 0)
{
readme().Run();
}
else
{
// close it
}
}
|
|
|
Goto Forum:
Current Time: Sat May 11 09:23:06 CEST 2024
Total time taken to generate the page: 0.02747 seconds
|