现在的位置: 首页 > 综合 > 正文

error C2110: cannot add two pointers

2013年09月15日 ⁄ 综合 ⁄ 共 522字 ⁄ 字号 评论关闭

      在MFC编程的时候,用到了字符串的输出,使用AfxMessageBox();,发现,在AfxMessageBox();中不能像控制台应用程序一样,将需要输出的内容使用“+”连接起来,调试的时候,会出现error C2110: cannot add two pointers的错误提示。

      在网上查找了一下解决的方式,其中有使用stringstream类型的解决方案,但是并不成功。因此使用Format()函数,错误提示消失。

      以CString的Format举例,第一个参数是格式化字符串,就像printf的第一个参数一样,用%d表示int,%s表示char*,%u表示unsigned int,%hd表示short,%hu表示unsigned short,%hhd表示char,%hhu表示unsigned char,%f表示float等。后面的参数就是与格式化字符串中每个字段对应的类型变量。 
      举例:
      int a = 10;
      int b = 100;
      CString str;
      str.Format("%d*%d=%d/n", a, b, a * b);
      那么输出就是10 * 100 = 1000

 

  

 

    

抱歉!评论已关闭.