VC字符串截取

来源:百度知道 编辑:UC知道 时间:2024/05/15 04:11:46
1.在VC中,如何从一个CString 定义的字符串中依次截取每一个字符并存入数组中。最终得到一个整形数组,其中的整形数的用于进行运算。
2.如何获取文本文件中内容存入数组。

楼上的办法是可以
不过麻烦了些

只要这样就行了 .

CString str ; //这是源
char* pStr = new char[ str.GetLength() + 1 ] ;
pStr = str.GetBuffer() ;
此时 pStr就指向了str 的首地址
下面用一个循环就能得到各个 字符了
for( int i = 0 ; i< str.GetLength() ; i++)
pStr[i] ; //pStr[i],就是各个字符了把这个放到你想放的数组中去

int pos = str.Find("&");
CString msg = str.Left(pos);
str = str.Right(str.GetLength() - pos -1 );
pos = str.Find("&");
CString datatime = str.Left(pos);
str = str.Right(str.GetLength() - pos -1 );
pos = str.Find("&");
CString username = str.Left(pos);
str = str.Right(str.GetLength() - pos -1 );
pos = str.Find("&");
CString group = str.Left(pos);
str = str.Right(str.GetLength() - pos -1 );
CString message = str.Left(pos);

CString year = datatime.Left(4);
datatime = datatime.Right(datatime.GetLength() - 4);
CString month = datatime.Left(2)