课设之百万数据文档存取

其他类型转换成string类型:

        string to_string (int val);
        string to_string (long val);
        string to_string (long long val);
        string to_string (unsigned val);
        string to_string (unsigned long val);
        string to_string (unsigned long long val);
        string to_string (float val);
        string to_string (double val);

        string to_string (long double val);


c_str()是Borland封装的String类中的一个函数,它返回当前字符串的首字符地址。当需要打开一个由用户自己输入文件名的文件时,可以这样写:ifstream in(st.c_str())


样例:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
string  a="outputdsaftttt.txt";
    ofstream output( a.c_str(), ios::out);
    if( ! output )
    {
        cerr << "Open output file error!" << endl;
        exit( -1 );
    }
    output.close();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sinat_36789271/article/details/79824109