⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buffers.cpp

📁 buffer example. buffer example. buffer example.
💻 CPP
字号:
// buffers.cpp
//
// Copyright (c) 2002 Symbian Ltd.  All rights reserved.
//

#include <e32base.h>
#include <e32cons.h>

LOCAL_D CConsoleBase* console;

// CBufBase demo - NOT Unicode safe!!
// Characters stored in 8 bits - just to demonstrate buffers
void printBuffer(CBufBase* aBuffer)
	{
	_LIT(KMsgBufEquals,"buffer=");
	console->Printf(KMsgBufEquals);
	TInt i=0;
	TPtrC8 p=aBuffer->Ptr(i);
	while (p.Length() > 0)
		{
		TBuf<4> temp; // Buffer (16 bits) needed for printing
		temp.Copy(p);
		_LIT(KBufFormatString,"[%S]");		
		console->Printf(KBufFormatString, &temp);
		i+=p.Length();
		p.Set(aBuffer->Ptr(i));
		};
	_LIT(KNewLine,"\n");
	console->Printf(KNewLine);
	}

void mainL()
	{
	CBufBase* buf=CBufSeg::NewL(4);
	CleanupStack::PushL(buf);
	//
	_LIT8(KTxt1,"hello!");
	buf->InsertL(0,KTxt1);
	printBuffer(buf);
	_LIT8(KTxt2," world");
	buf->InsertL(5,KTxt2); // "hello world!"
	printBuffer(buf); 
	buf->Delete(2,7); // "held!"
	printBuffer(buf);
	buf->Compress();
	printBuffer(buf);
	buf->ExpandL(2,7); // "he.......ld!"
	printBuffer(buf);
	_LIT8(KTxt3,"llo wor");
	buf->Write(2,KTxt3);
	printBuffer(buf);
	//
	CleanupStack::PopAndDestroy(); // buf
	}

// Console harness

void consoleMainL()
    {
	// Get a console
	_LIT(KMsgTitle,"Buffers example");
	console=Console::NewL(KMsgTitle,TSize(KConsFullScreen,KConsFullScreen));
	CleanupStack::PushL(console);
	// Call function
	mainL();
	// Wait for key
	_LIT(KMsgPressAnyKey,"[ press any key ]");
	console->Printf(KMsgPressAnyKey);
	console->Getch(); // Get and ignore character
	// Finished with console
	CleanupStack::PopAndDestroy(); // Console
    }

// Cleanup stack harness
GLDEF_C TInt E32Main()
    {
	__UHEAP_MARK;
	CTrapCleanup* cleanupStack=CTrapCleanup::New();
	TRAPD(error,consoleMainL());
	__ASSERT_ALWAYS(!error, User::Panic(_L("SCMP"), error));
	delete cleanupStack;
	__UHEAP_MARKEND;
	return 0;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -