我要在win32下使用CString,应该包含什么头文件
另外string有没有办法把double float int 等其他类型的转换为string 或者char*

解决方案 »

  1.   

    使用C中的转换函数呀.atoi,itoa....等等.
      

  2.   

    将其他类型转换到string ,需要使用C函数的类型转换库
    CString需要包含 Afx.h
    该类是MFC的东西
      

  3.   

    不行啊!
    错误提示如下:
    fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>
      

  4.   

    #include "stdafx.h"在stdafx.h中:
    //#include <windows.h>
    #include <afx.h>
      

  5.   

    你的工程可能不是支持MFC的,最简单的做法是重建一个使用MFC的project,然后复制代码。也可以着一个MFC的project例子,将他的stdafx.h替换现在的stdafx.h
      

  6.   

    include "string.h"
    sring t,
    t.format("%d,%f",1,1.01);
    try it!
      

  7.   

    MFC工程不需要包含什么,直接使用CString.
      

  8.   

    include "string.h"
    sring t,
    t.format("%d,%f",1,1.01);
    try it!
    瞎说吧
      

  9.   

    你的工程可能不是支持MFC的,最简单的做法是重建一个使用MFC的project,然后复制代码。也可以着一个MFC的project例子,将他的stdafx.h替换现在的stdafx.h
    **********
    不是不支持,而是他的根本就是mfc的,
    ==》
    MFC apps must not #include <windows.h>
    在mfc下是不能再包含windows.h的。直接可以使用CString的了。
      

  10.   

    http://blog.csdn.net/horisly/articles/378796.aspx
    对论坛中有关数据类型转换的总结
      

  11.   

    楼上的各位都说的很清楚了。
    1 在VC中只要#include <afx.h>(而不是string.h)就可以用CString对象了,除非楼主的工程不支持MFC(解决方法见orbit(走了走了) 的答复)。
    2 数据类型转换(转换时要用到string.h了):
      int,long-->string
             CString str;
             str.Format("%d",此处用你的int或long变量代替);
        char*--->string
             CString str;
             char* s="My string.";
             str=s
        string--->char*  
             CString str;
             str="My string.";
    char* s=new char[100];
    strcpy(s,str);另外:
    To:  orbit(走了走了) 
    怎样才能看到MFC系统函数如GetAsSystemTime的源代码,我用F12键只能看到它们的函数原型。
    呵呵,不好意思!在另外一个问题贴中也问了这个问题,现在又追到这里来问了,请指点一下小弟呀!