#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<time.h>
#include<conio.h>
#include<fstream.h>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<iomanip.h>
#include<afx.h>
#include<string>
using namespace std;string ConvertToString(int X)
{
string Result; int i, Counter;
char C_quotient[10];
div_t div_result; Counter=0; for(i=0;i<4;i++)
{
div_result = div( X, pow(10.0, (4-i)));
if(div_result.quot>0||Counter>0)
{
C_quotient[Counter]=48+div_result.quot;
Counter++;
}
X=div_result.rem;
} C_quotient[Counter]=48+div_result.rem; //the last number for(i=0;i<=Counter;i++)
Result=Result+C_quotient[i]; return Result;}void main()
{
int a=2;
string The_Route="E:\\literature\\"+ConvertToString(a)+"\\";
cout<<The_Route<<endl;//我想把The_Route的值输出来,可是不能用cout?
}
int转为string的函数是我copy的别人的,我需要把路径输出来,可是出不来?

解决方案 »

  1.   

    附注另外一个问题:原程序很大,后来修改时候,需要用到int转成string的方法,于是在头文件中加了#include<string>
    using namespace std;运行确发现错误:
    F:\hust\IRP\VRPTW_TS\VRPTW_禁忌搜索.CPP(172) : error C2872: 'ifstream' : ambiguous symbol
    F:\hust\IRP\VRPTW_TS\VRPTW_禁忌搜索.CPP(1282) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptab
    le conversion)
    F:\hust\IRP\VRPTW_TS\VRPTW_禁忌搜索.CPP(1286) : error C2872: 'ifstream' : ambiguous symbol
    F:\hust\IRP\VRPTW_TS\VRPTW_禁忌搜索.CPP(1286) : error C2664: '__thiscall ifstream::ifstream(const char *,int,int)' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const 
    char *'
            No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    F:\hust\IRP\VRPTW_TS\VRPTW_禁忌搜索.CPP(1287) : error C2872: 'ifstream' : ambiguous symbol
    F:\hust\IRP\VRPTW_TS\VRPTW_禁忌搜索.CPP(1287) : error C2664: '__thiscall ifstream::ifstream(const char *,int,int)' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const 
    char *'
            No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    F:\hust\IRP\VRPTW_TS\VRPTW_禁忌搜索.CPP(1288) : error C2872: 'ofstream' : ambiguous symbol
    F:\hust\IRP\VRPTW_TS\VRPTW_禁忌搜索.CPP(1288) : error C2664: '__thiscall ofstream::ofstream(const char *,int,int)' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const 
    char *'
            No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    执行 cl.exe 时出错.
      

  2.   

    #include<string>
    去掉这个头文件,把string类型全改成CString类型,这个比较方便,至于string好象还得设些东西,至于还设什么我不清楚
      

  3.   

    char *_itoa(
       int value,
       char *str,
       int radix 
    );
    char *_i64toa(
       __int64 value,
       char *str,
       int radix 
    );
    char * _ui64toa(
       unsigned _int64 value,
       char *str,
       int radix 
    );
    wchar_t * _itow(
       int value,
       wchar_t *str,
       int radix 
    );
    wchar_t * _i64tow(
       __int64 value,
       wchar_t *str,
       int radix 
    );
    wchar_t * _ui64tow(
       unsigned __int64 value,
       wchar_t *str,
       int radix 
    );
    template <size_t size>
    char *_itoa(
       int value,
       char (&str)[size],
       int radix 
    ); // C++ only
    template <size_t size>
    char *_i64toa(
       __int64 value,
       char (&str)[size],
       int radix 
    ); // C++ only
    template <size_t size>
    char * _ui64toa(
       unsigned _int64 value,
       char (&str)[size],
       int radix 
    ); // C++ only
    template <size_t size>
    wchar_t * _itow(
       int value,
       wchar_t (&str)[size],
       int radix 
    ); // C++ only
    template <size_t size>
    wchar_t * _i64tow(
       __int64 value,
       wchar_t (&str)[size],
       int radix 
    ); // C++ only
    template <size_t size>
    wchar_t * _ui64tow(
       unsigned __int64 value,
       wchar_t (&str)[size],
       int radix 
    ); // C++ only
      

  4.   

    先把int转化为 char* 然后转化成string
      

  5.   


    int a=2;
    char buf[50];
    sprintf_s(buf,50,"%d",a);