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

📄 strings.cpp

📁 symbina strings example. symbian strings example.
💻 CPP
字号:
// strings.cpp
//
// Copyright (c) 2000 Symbian Ltd.  All rights reserved.
//

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

LOCAL_D CConsoleBase* console;

// this program is best appreciated from inside a debugger

// function showing how to pass modifiable and constant string parameters

void greetEntity(TDes& aGreeting, const TDesC& aEntity)
	{
	aGreeting.Append(aEntity);
	}

// real main function

void mainL()
    {
	// health warning
	console->Printf(_L("Your home is at risk if you do not keep up repayments on your mortgage!\n"));
	console->Printf(_L("Smoking is dangerous and can damage your health!\n"));
	console->Printf(_L("The value of investments can go down as well as up!\n"));
	console->Printf(_L("This program is best appreciated from inside a debugger!\n"));
	// string in program text
	_LIT(KHelloRom, "hello");
	TPtrC helloPtr(KHelloRom);
	// string on stack
	TBufC<5> helloStack(KHelloRom);
	// string on heap
	HBufC* helloHeap=KHelloRom().AllocLC();
	// concatenating onto the stack
	_LIT(KWorldRom, " world!");
	TBuf<12> helloWorldStack(KHelloRom);
	helloWorldStack.Append(KWorldRom);
	// concatenating onto the heap
	HBufC* helloWorldHeap=HBufC::NewMaxLC(KHelloRom().Length()+KWorldRom().Length());
	TPtr helloWorldAppend=helloWorldHeap->Des();
	helloWorldAppend=KHelloRom;
	helloWorldAppend.Append(KWorldRom);
	// using a function which manipulates strings
	TBuf<12> helloWorld(_L("hello"));
	greetEntity(helloWorld,_L(" world!"));
	// _LIT literal
	const TDesC& helloRef=KHelloRom;
	// delete strings we allocated
	CleanupStack::PopAndDestroy(2);
	}

// console harness

void consoleMainL()
    {
	// get a console
	console=Console::NewL(_L("Strings"),TSize(KConsFullScreen,KConsFullScreen));
	CleanupStack::PushL(console);
	// call function
	mainL();
	// wait for key
	console->Printf(_L("[ press any key ]"));
	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 + -