mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-29 06:12:18 -06:00
.tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@11482 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
8fa242b083
commit
08d5d416e0
5 changed files with 210 additions and 0 deletions
73
tutorial/CoreTutorial/Stream.cpp
Normal file
73
tutorial/CoreTutorial/Stream.cpp
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#include "Tutorial.h"
|
||||
|
||||
void Stream()
|
||||
{
|
||||
/// .Streams basics
|
||||
|
||||
FileIn in(GetDataFile("test.txt"));
|
||||
if(!in) {
|
||||
LOG("Failed to open the file");
|
||||
return;
|
||||
}
|
||||
|
||||
String h;
|
||||
int c;
|
||||
while((c = in.Get()) >= 0)
|
||||
h.Cat(c);
|
||||
DUMP(h);
|
||||
|
||||
in.Seek(0);
|
||||
while(!in.IsEof())
|
||||
DUMP(in.GetLine());
|
||||
|
||||
in.Seek(0);
|
||||
DUMP(in.Get(10));
|
||||
|
||||
in.Seek(0);
|
||||
DUMP(in.Get(999999).GetCount());
|
||||
|
||||
in.Seek(0);
|
||||
h = in.GetAll(100);
|
||||
DUMP(h.GetCount());
|
||||
h = in.GetAll(999999);
|
||||
DUMP(h.IsVoid());
|
||||
in.LoadThrowing();
|
||||
try {
|
||||
in.GetAll(999999);
|
||||
}
|
||||
catch(LoadingError) {
|
||||
LOG("Loading error");
|
||||
}
|
||||
|
||||
String fn = GetHomeDirFile("test");
|
||||
FileOut out(fn);
|
||||
if(!out) {
|
||||
LOG("Failed to open the file");
|
||||
return;
|
||||
}
|
||||
out << "Some number " << 321 << " and Point " << Point(1, 2);
|
||||
out.Close();
|
||||
if(out.IsError()) { // check whether file was properly written
|
||||
LOG("Error");
|
||||
return;
|
||||
}
|
||||
DUMP(LoadFile(fn));
|
||||
|
||||
FileAppend out2(fn);
|
||||
out2 << "\nSomething more";
|
||||
out2.Close();
|
||||
DUMP(LoadFile(fn));
|
||||
|
||||
StringStream ss;
|
||||
ss.Put32le(0x12345678);
|
||||
ss.Put32be(0x12345678);
|
||||
|
||||
StringStream ss2(ss.GetResult());
|
||||
DUMP(ss.Get32le());
|
||||
DUMP(ss.Get32be());
|
||||
DUMPHEX(ss.GetResult());
|
||||
|
||||
|
||||
|
||||
///
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue