真搞不懂,为毛C++这么多类型转换。。

CString m_str(_T("fuck conversion"));

char *chr=new char[m_str.GetLength()+1];
WideCharToMultiByte(CP_ACP,0,m_str.GetBuffer(),-1,chr,m_str.GetLength()+1,NULL,NULL);
string str=chr;

cout<<str;

2、char转string

char ch[10] = {0};

itoa(i, ch, 10);

std::string str = (char *)ch;

3、int转byte

public byte[] intToByte(int i) {
        byte[] abyte0 = new byte[4];
        abyte0[0] = (byte) (0xff & i);
        abyte0[1] = (byte) ((0xff00 & i) >> 8);
        abyte0[2] = (byte) ((0xff0000 & i) >> 16);
        abyte0[3] = (byte) ((0xff000000 & i) >> 24);
        return abyte0;
    }
4、byte转int
public  static int bytesToInt(byte[] bytes) {
        int addr = bytes[0] & 0xFF;
        addr |= ((bytes[1] << 8) & 0xFF00);
        addr |= ((bytes[2] << 16) & 0xFF0000);
        addr |= ((bytes[3] << 24) & 0xFF000000);
        return addr;
    }

最新文章

  1. SpringMVC+Shiro权限管理【转】
  2. c++中的重名问题
  3. 【JAVA】LOG4J使用心得
  4. spring MVC 详细入门
  5. 使用grep恢复被删除文件内容【转】
  6. 【转】禁止seekbar的拖动事件
  7. 【转】Mac访问Windows共享文件夹
  8. 【转】Linux 上的最佳 C/C++ IDE
  9. &lt;c&gt;----&lt;choose&gt;&lt;when&gt;&lt;otherwise&gt;
  10. django之快速分页
  11. jquery总结(来自于一个讲师的总结)
  12. Javaweb 项目内所有页面都是404问题
  13. 线程池ThreadPoolExecutor源码解读研究(JDK1.8)
  14. Mysql锁机制--并发事务带来的更新丢失问题
  15. Gym 102091L Largest Allowed Area 【二分+二维前缀和】
  16. MT7628如何配置使用 Openwrt路由模式 (校园网配置)
  17. Linux日志文件总管——logrotate
  18. 2018.10.08 NOIP模拟 斐波那契(贪心+hash/map)
  19. g2o error2
  20. mysql的一些规范

热门文章

  1. Dijkstra+SPFA 模板
  2. SpringCloud(一)
  3. java课程学习心得
  4. Keras高层API之Metrics
  5. javaweb实现注册页面(数据库连接以及ajax验证)
  6. MySQL在大数据、高并发场景下的SQL语句优化和&quot;最佳实践&quot;
  7. P4072 [SDOI2016]征途
  8. npm ERR! Cannot read property &#39;match&#39; of undefined
  9. 使用IntersectionObserver制作滚动动画以及其他记录
  10. exe 发布为服务