本人使用string从文本中读入一段字符串 int L_KorM_Flag;
int L_xPos_key;
int L_yPos_keyUD;
int L_Sleep_second; TCHAR L_TempBmpPath[MAX_PATH]; //这里被定义 string Title_line;
getline(in, Title_line); for(string Sline; getline(in, Sline);)
{
istringstream Read_Line(Sline);
string TempBmpPath;//使用流读入
Read_Line>>L_KorM_Flag>>L_xPos_key>>L_yPos_keyUD>>L_Sleep_second>>TempBmpPath; ...........
//?这里执行字串存储操作,怎么把TempBmpPath存入L_TempBmpPath AP_Control_List.push_back( List_line );
}
谢谢,问题有关立即结贴给分!
int L_xPos_key;
int L_yPos_keyUD;
int L_Sleep_second; TCHAR L_TempBmpPath[MAX_PATH]; //这里被定义 string Title_line;
getline(in, Title_line); for(string Sline; getline(in, Sline);)
{
istringstream Read_Line(Sline);
string TempBmpPath;//使用流读入
Read_Line>>L_KorM_Flag>>L_xPos_key>>L_yPos_keyUD>>L_Sleep_second>>TempBmpPath; ...........
//?这里执行字串存储操作,怎么把TempBmpPath存入L_TempBmpPath AP_Control_List.push_back( List_line );
}
谢谢,问题有关立即结贴给分!
error C2664: 'memcpy' : cannot convert parameter 2 from 'unsigned int' to 'const void *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast怎么搞?
第三个参数是大小
memcpy(L_TempBmpPath,TempBmpPath.c_str(),TempBmpPath.size())
测试过了,编译没问题,但是L_TempBmpPath存的字串不对;例如流读入放入“hello”,使用此方法后就乱码了本人做wince程序设计,使用unicode;求转化详解谢谢大家!
TCHAR L_TempBmpPath[MAX_PATH]; //这里被定义,保证MAX_PATH内存大小足够大void string2wstring(string str,L_TempBmpPath)
{
//获取缓冲区大小,并申请空间,缓冲区大小按字符计算
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0);
TCHAR* buffer = new TCHAR[len + 1];
//多字节编码转换成宽字节编码
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len);
buffer[len] = '\0'; //添加字符串结尾
//删除缓冲区并返回值
strcpy(L_TempBmpPath,buffer, len + 1) //这里将转换后的TCHAR赋给你要的内存段
delete[] buffer;
}
同类型的赋值或拷贝下就行了。string2wstring函数里的用完会释放,所以指针赋值应当心点
#include <atlbase.h>
USES_CONVERSION;
A2T();
WideCharToMultiByte()在string 和wstring间进行华丽转换
const void * 这个指针没有分配内存,你要复制string 到指针中,当然要分配内存了。你也可以用C语言
wsprintf(targetstring,sourcestring,parameters)这个函数