804 Star 2.4K Fork 1.2K

GVPHuawei LiteOS / LiteOS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
TestClass.cpp 2.03 KB
一键复制 编辑 原始数据 按行查看 历史
tinyfrog 提交于 2020-12-26 19:18 . update doc info
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*/
#include "los_cppsupport.h"
#include<iostream>
#include<map>
#include<string>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
using namespace std;
class TestClass {
public:
TestClass(int arg);
~TestClass(void);
void PrintTest(void);
void StringTest(void);
void MapTest(void);
private:
int intTest;
string stringTest;
map<string, int> mapTest;
};
TestClass::TestClass(int arg)
{
cout << "TestClass is constructed here, arg = " << arg << endl;
intTest = arg;
}
TestClass::~TestClass(void)
{
cout << "TestClass is destructed" << endl;
}
void TestClass::PrintTest(void)
{
cout << __FUNCTION__ << " enter" << endl;
cout << " intTest = " << this->intTest << endl;
}
void TestClass::StringTest(void)
{
cout << __FUNCTION__ << " enter" << endl;
string a("Lite");
string b("OS");
string c("LiteOS");
if (a != b) {
cout << " " << a << " != " << b << endl;
}
a += b;
if (a == c) {
cout << " " << a << " == " << c << endl;
}
}
void TestClass::MapTest(void)
{
cout << __FUNCTION__ << " enter" << endl;
mapTest.insert(pair<string, int>("Huawei", 1));
mapTest.insert(pair<string, int>("LiteOS", 2));
mapTest.insert(pair<string, int>("Open", 3));
mapTest.insert(pair<string, int>("Source", 4));
cout << " show map key&value" << endl;
for (auto &it : mapTest) {
cout << " " << it.first << " " << it.second << endl;
}
mapTest["LiteOS"] = 8; /* 8: new value */
cout << " change value of \"LiteOS\" key" << endl;
for (auto &it : mapTest) {
cout << " " << it.first << " " << it.second << endl;
}
}
void CppTestEntry(void)
{
cout << "LiteOS cpp sample start" << endl;
TestClass test(123);
test.PrintTest();
test.StringTest();
test.MapTest();
cout << "LiteOS cpp sample stop" << endl;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
C
1
https://gitee.com/LiteOS/LiteOS.git
git@gitee.com:LiteOS/LiteOS.git
LiteOS
LiteOS
LiteOS
master

搜索帮助