你好,這裏是我的代碼片段:如何將C++流與c_str()庫API一起使用。
RIT128x96x4StringDraw(HWREGBITW(&g_ulFlags, 0) ? "1" : "0", 48, 32, 15);
這僅用於打印屏幕上的一些字符串。 我希望有一個功能或裝置打印可increamented numericals,就像我們在C++做
for(;;)
{
cout<<i++;
}
你好,這裏是我的代碼片段:如何將C++流與c_str()庫API一起使用。
RIT128x96x4StringDraw(HWREGBITW(&g_ulFlags, 0) ? "1" : "0", 48, 32, 15);
這僅用於打印屏幕上的一些字符串。 我希望有一個功能或裝置打印可increamented numericals,就像我們在C++做
for(;;)
{
cout<<i++;
}
從您的其他問題Arm Cortex Display,我們看到函數的原型。
void RIT128x96x4StringDraw(char *str, ulong x, ulong y, unsigned char level);
下面是參數,
x
和y
在屏幕上的位置。他們是字符位置,所以此功能繪製文本,如printf()
或cout
。level
參數是強度;我猜你有一個灰度級液晶顯示器,這是如何白色或黑色的文字是。str
是一個C字符串您希望打印。下面是一個樣本,它將以傳統的C模式打印一個數字。
#include <stdio.h>
#include <stdlib.h>
void print_number(int i)
{
char buffer[36];
itoa (i,buffer,10);
RIT128x96x4StringDraw(&buffer[0], 0, 0, 15);
}
它使用itoa()
功能的數字轉換爲C字符串。如果你喜歡C++ syntax,下面的代碼可以是更優選,
void print_number(int i)
{
std::ostringstream oss;
oss << i++;
/* What ever else you wish to do... */
RIT128x96x4StringDraw(oss.str().c_str(), 0, 0, 15);
}
此代碼並不意味着是防彈的生產代碼,不得編譯。這是爲了展示一個概念。
如果您的目標是資源受限,那麼這裏是一個implementation of itoa()
。
感謝法案工作並解決了我的問題 – user2159417 2013-03-14 05:02:24
您的目標是否提供'sprintf()'函數? – nos 2013-03-14 01:40:20
NO IT DOESNOT提供此功能 – user2159417 2013-03-14 05:03:08
是的,我檢查它有一個函數usprintf() – user2159417 2013-03-14 05:27:24