输入字符串到文件

#include 
#include 
#include 

using namespace std;
void main()
{
    ofstream outfile("C:\\Users\\PC\\Desktop\\oooo.txt", ios::out);
    if (!outfile)
    {
        cerr << "open text.txt error" << endl;
        exit(0);
    }
    char c[80];
    cout << "enter a sentence:";
    cin.getline(c, 30);
    for (int i = 0; c[i] != 0; i++)
    {
        outfile.put(c[i]);

    }
    outfile.close();
    cout << c << endl;
    system("pause");
}

你可能感兴趣的:(c++相关)