【发布时间】:2016-06-13 15:17:32
【问题描述】:
大多数时候,当我需要标准库中没有实现的特定功能时,我会尝试自己实现它。我还创建静态库来使用和重用代码。
所以我正在考虑编写一个独立于标准库的测试程序。该程序缺少打印功能。打印通常是计算机程序的主要部分。
像putchar() 或cout 这样简单的打印功能如何用C 或C++ 实现?
我的代码:
#define TRUE 1
#define FALSE 0
typedef int INT_32;
typedef unsigned int size_t;
struct block {
INT_32 v;
size_t x;
};
void f1(struct block *s);
int f2(void *addr);
int main(void)
{
struct block blk;
f1(&blk);
//print blk members
int res = f2(&blk);
// print res
return 0;
}
void f1(struct block *s)
{
s->v = -1;
s->x = 1
}
int f2(void *addr)
{
if (addr) {
return TRUE;
}
else {
return FALSE;
}
}
【问题讨论】:
-
C 和 C++ 是不同的语言。选一个。如果已经有标准的,不要定义自制布尔常量或类型。
-
取决于系统。哪个系统?
-
@Cheersandhth.-Alf,Windows 或 Linux..
-
在这种情况下
write。在 Windows 中,您将使用WriteFile进行流输出或使用WriteConsole...进行直接控制台窗口输出。 -
@Cheersandhth.-Alf :在评论中要求澄清是有效的,但如果澄清导致答案,您应该发布答案而不是在评论中回答。
标签: c++ c linux windows printing