我的計劃(C++):如何保存文本文件而不在末尾鍵入「.txt」?
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
float x, y, z;
char d[20];
int main()
{
cin.getline >>d;
x=111;
y=222;
z=333;
ofstream meuarquivo;
meuarquivo.open (d".txt");
meuarquivo << x << "\n";
meuarquivo << y << "\n";
meuarquivo << z << "\n";
meuarquivo.close();
return 0;
}
我想寫類似「ThatsMyProgram」,我想程序將此文件保存爲「ThatsMyProgram.txt」。我怎樣才能做到這一點?
有沒有你正在使用一個char []爲保持輸入,你能不能從標準庫使用字符串什麼特別的原因? – DaveJohnston 2011-03-22 15:05:42