本人使用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 );  
}
谢谢,问题有关立即结贴给分!

解决方案 »

  1.   

    memcpy(L_TempBmpPath, TempBmpPath.size(), TempBmpPath.c_str()) ;?
      

  2.   

    如果你的程序是unicode的话,还需要用到mutlichartowidechar类似的函数
      

  3.   


    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怎么搞?
      

  4.   

    memcpy(pDst, pSrc, nSize)
    第三个参数是大小
      

  5.   

    嗯,这样写:
    memcpy(L_TempBmpPath,TempBmpPath.c_str(),TempBmpPath.size())
    测试过了,编译没问题,但是L_TempBmpPath存的字串不对;例如流读入放入“hello”,使用此方法后就乱码了本人做wince程序设计,使用unicode;求转化详解谢谢大家!
      

  6.   

    string.c_str() 得到的是 char数组wstring.c_str() 得到的是 wchar_t数组1.如果可以使用wstring读取的话就ok了2.如果不能是用wstring读取的话,就要用 MultiByteToWideChar函数来进行编码转换
      

  7.   


    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;   
     }   
      

  8.   

    strcpy或者memcpy之类的函数你试试看吧。
    同类型的赋值或拷贝下就行了。string2wstring函数里的用完会释放,所以指针赋值应当心点
      

  9.   

    Unicode编码下,使用MultiByteToWideChar,mbstowcs()
    #include <atlbase.h>
    USES_CONVERSION;
    A2T();
      

  10.   

    使用MultiByteToWideChar() 和
    WideCharToMultiByte()在string 和wstring间进行华丽转换
      

  11.   


    const void * 这个指针没有分配内存,你要复制string 到指针中,当然要分配内存了。你也可以用C语言
    wsprintf(targetstring,sourcestring,parameters)这个函数