pingkai1217 2016-03-04 11:28 采纳率: 41.7%
浏览 2916
已采纳

C++ 字符串 转 二维数组

 CString  aa = "11<225>22<225>33<225>44<000>aa<225>bb<225>cc<225>dd<000>ee<255>ff<255>hh<000>"想转为二维数组   求代码 学习

想转为二维数组 求代码 学习

  • 写回答

2条回答 默认 最新

  • threenewbee 2016-03-04 16:31
    关注
     // app1.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include "app1.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // The one and only application object
    
    CWinApp theApp;
    
    using namespace std;
    
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
        int nRetCode = 0;
    
        // initialize MFC and print and error on failure
        if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
        {
            // TODO: change error code to suit your needs
            cerr << _T("Fatal Error: MFC initialization failed") << endl;
            nRetCode = 1;
        }
        else
        {
            // TODO: code your application's behavior here.
            //CString strHello;
            //strHello.LoadString(IDS_HELLO);
            //cout << (LPCTSTR)strHello << endl;
            CString aa = "11<225>22<225>33<225>44<000>aa<225>bb<225>cc<225>dd<000>ee<255>ff<255>hh<000>";
    
            char * buffer = new char[aa.GetLength() + 1];
            strcpy(buffer, (LPCTSTR)aa);
            char ** arr = new char*[aa.GetLength()];
            int n = 1;
            arr[0] = &buffer[0];
            for (int i = 0; i < aa.GetLength(); i++)
            {
                if (buffer[i] == '<' || buffer[i] == '>')
                {
                    arr[n] = &buffer[i + 1];
                    buffer[i] = '\0';
                    n++;
                }
            }
            for (i = 0; i < n - 1; i++)
            {
                printf("%s\n", arr[i]);
            }
        }
    
        return nRetCode;
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?