我的计划(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