#pragma once#include <string> namespace stds { class tool { public: std::string ws2s(const std::wstring& ws) { std::string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C"; setlocale(LC_ALL, "chs"); const wchar_t* _Sou…
https://github.com/yaowenxu/Workplace/blob/master/timer/getrusagetimer.c 关键结构体: struct rusage { struct timeval ru_utime; /* user time used */ struct timeval ru_stime; /* system time used */ long ru_maxrss; /* max resident set size */ long ru_ixrss; /…
uses psapi; {根据进程PID获取程序所在路径的函数}function GetProcessExePath(PID: Cardinal): string;varpHandle: THandle;buf: array[0..MAX_PATH] of Char;begin{获取进程句柄}pHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);{获取进程路径}GetModuleFileN…
下面程序演示了在嵌入式Linux和PC机Linux下使用popen函数时,程序的运行结果是有差异的. 两个程序 atest.c 和 btest.c,atest 检查是否有 btest 进程运行,如果没有就执行 btest 然后退出,如果有就直接退出.atest在检查时输出 btest 进程数,PC机是buf 值,但嵌入式是buf值减1,为什么?后面说明. atest.c 源代码: #include <stdio.h> #include <sys/time.h> static int…
使用c_str()函数 c_str函数的返回值是const char*. c_str()函数返回一个指向正规C字符串的指针, 内容与本string串相同. 这是为了与c语言兼容,在c语言中没有string类型,故必须通过string类对象的成员函数c_str()把string 对象转换成c中的字符串样式. 举个栗子: String st = ] + ] + "','" + str_time + "')"; const char* sql1 = st.c_str();…
EXE文件的存储路径,不太受调用时环境变量的影响: Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); EXE文件的运行路径,如果不知双击打开的,而是用其他程序调用的,返回的不一定是EXE的存储路径: System.Windows.Forms.Application.StartupPath;…
VC++编程中经常遇到不同编码编码的字符串之间需要转换的情况,以下简单提供几个不同编码字符串之间的转换函数: ANSI 字符串和Unicode字符串之间的转换 //Convert wide char string to ANSI string BOOL WCharToMByte(LPCWSTR lpcwszStr,Std::string &str) { DWORD dwMinSize=; LPSTR lpszStr=NULL; dwMinSize= WideCharToMultiByte(CP_…
继上集故事<多字符集(ANSI)和UNICODE及字符串处理方式准则 >,我们现在有一些特殊需求: 有时候我们的字符串是多字符型,我们却需要使用宽字符型:有的时候却恰恰相反. Windows为我们提供了这样的函数来处理这个问题: 1.MultiByteToWideChar 函数功能: 该函数映射一个字符串到一个宽字符 (unicode)的字符串.由该函数映射的字符串没必要是多字节字符组. 函数原型: int MultiByteToWideChar(UINT CodePage, DWORD dw…
Convert CString to ANSI string in UNICODE projects Quick Answer: use an intermediate CStringA. Normally, this is not something that should be done. *It is technically unreliable, unless you can guarantee that the source CString to be converted does n…
/// <summary> Convert a string of hex digits (ex: E4 CA B2) to a byte array. </summary> /// <param name="s"> The string containing the hex digits (with or without spaces). </param> /// <returns> Returns an array of…