首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请高手看一下小弟我写的c++函数

2012-03-06 
请高手看一下我写的c++函数intcreate(){strings,namecharfn n cout 请输入文件名: endlcin

请高手看一下我写的c++函数
int   create()  
{string   s,name;  
char   fn= 'n ';  
cout < < "请输入文件名: " < <endl;  
cin> > name;  
ofstream   outfile( "name ",ios::out);  
while((fn== 'n ')||(fn== 'N '))  
{cout < < "输入一行文本: " < <endl;  
cin> > s;  
outfile < <s < <endl;  
cout < < "结束输入吗?   y   or   n   ? " < <endl;  
cin> > fn;  
}  
cout < < "文件建立成功! " < <endl;  
return   0;  
}  


ofstream   outfile( "name ",ios::out);如果这样就不能创建文件,但编译不出错。如果改成   ofstream   outfile( "f1.txt ",ios::out);就能成功。  
请问怎么实现从键盘上输入文件名?  


[解决办法]
ofstream outfile( "name ",ios::out);
==>
ofstream outfile(name,ios::out);

[解决办法]
#include <string>
#include <iostream>
using namespace std;

void main( )
{ string word;
while(cin> > word){
word+= " ";
cout < <word;
}
}

热点排行