美文网首页
C++ 中一些问题记录

C++ 中一些问题记录

作者: Gavin_2020 | 来源:发表于2020-09-25 11:24 被阅读0次

一、在编译成.so之后再android中打印c++的信息

引入头文件:


#include <android/log.h>

    #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))

    #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))

    #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))

    #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))

以上打印方法建议使用error形式,因为部分机型debug以及其他类型的打印优先级较低,有的甚至不会输出打印信息.

在需要打印的地方使用:

LOGD("height:%d",height);

这里选用%d格式化了打印数据也可以根据需求自己修改。

打印结果例如: heght: 300

二、判断是否为中文


bool CRecognizer::IsChineseChar(WORD DoubleByte)

{

  //unicode中文字符范围为4e00-9fa5

  BYTE LowByte = LOBYTE(DoubleByte);

  BYTE HighByte = HIBYTE(DoubleByte);

  if (HighByte == 0x9f) return (LowByte <= 0xa5);

  else  return (HighByte >= 0x4e && HighByte < 0x9f);

}

三、大小写转换


wchar_t* jstringToCap(JNIEnv*env, jstring jstr)

{

if(jstr==0)

return 0;

int length = env->GetStringLength(jstr);

if (length==0)

{

return 0;

}

const jchar* jcstr = env->GetStringChars(jstr, 0 );

wchar_t* rtn = new wchar_t[length+1];

for(int i=0;i<length;i++){

if (jcstr[i] >= 'a' && jcstr[i] <= 'z')

{

rtn[i]=jcstr[i]+('A'-'a');

}else

rtn[i]=jcstr[i];

}

env->ReleaseStringChars(jstr, jcstr );

rtn[length] = 0;

return rtn;

}

四. C++保存时间戳命名图片到android目录下

// 获取时间戳
time_t now;
struct tm *timenow;
time(&now);
timenow = localtime(&now);
long sec = timenow ->tm_sec;
long min = timenow->tm_min;
// 格式化androd存储地址(需要strtowst也就是转化为宽字符串形式)
char buff2[1024] = { 0 };
sprintf(buff2, "/storage/emulated/0/Android/idcardCrop/dest_img_%d_%d.jpg", min,sec);
std::wstring wstr = StringFormat::strtowstr(buff2);
// 写入图片
tmpimg.imwrite(wstr.c_str(),0);

持续记录更新中。。

相关文章

  • Android NDK编程碰到的一些问题

    在jni编程中,牵涉到java字符串转化为c/c++字符串时,碰到了一些问题,挺奇葩,记录下来。 首先文件结构形式...

  • C++的学习记录 -- 项目配置tasks.json 和 lau

    最近在学习C++,在此记录过程中遇到的一些问题。环境搭建就不写了,一般程序的操作,我是安装在其他盘的目录,安装教程...

  • FFmpeg视频播放

    首先记录一下C++中的NULL、0、nullptr的区别 NULL在C++中就是0,这是因为在C++中void* ...

  • C++ 中一些问题记录

    一、在编译成.so之后再android中打印c++的信息 引入头文件: 在需要打印的地方使用: 二、判断是否为中文...

  • 关于const的那些事

    最近在通过 C++ Primer 这本书复习C++。在看到const这一节中,看到了很多容易混淆的几个点,因此记录...

  • spring boot2集成activiti6的问题记录

    最近集成activi 6集成到spring boot中,遇到一些问题,记录一二. activiti中的mybait...

  • C++之基本内置类型(2.1)

    声明:本文是学习《C++ Primer》(王刚 杨巨峰译)过程中记录下的摘抄笔记。感谢两位译者翻译之功! C++定...

  • 尝鲜c++踩坑合集_0neBean_NOTE

    在家自学了一段时间c++.其中遇到了一些问题,及思考过程,记录下来和大家探讨一下. 1: c++的模板不支持分离文...

  • Android-NDK开发-利用fmod实现变声

    最近在学NDK开发,自己在接触一些第三方开源C/C++库的时候,会碰到一些问题,这里记录下来,就相当于笔记了。废话...

  • electron 问题汇总

    此博客记录了使用 electron[https://www.electronjs.org/] 过程中遇到的一些问题...

网友评论

      本文标题:C++ 中一些问题记录

      本文链接:https://www.haomeiwen.com/subject/ldxfuktx.html