I have always had problems with file output and input in C++. For some reason i just cant understand it. But I have a problem (yes, for a class.. I know. I already feel bad but the professor isn't much help) on this function I'm working on for a menu.
我一直遇到文件输出和C ++输入问题。出于某种原因,我无法理解它。但我有一个问题(是的,对于一个班级......我知道。我已经感觉很糟糕,但教授没有太多帮助)这个功能我正在努力做菜单。
Here's what i've got so far.
这是我到目前为止所拥有的。
void addName(){
string name;
ofstream outfile;
cout << "Please type a name you would like to add:";
outfile.open("file.txt", std::ios_base::app);
cin >> name;
outfile << name;
cout << "Name added!" << endl;
}
I call this into my main
thing. Sorry for my amateur-ness.
我称之为我的主要内容。对不起我的业余爱好者。
The question is how can I append "names" to my file.txt
?
问题是如何将“名称”附加到我的file.txt?
Screenshots :
http://gyazo.com/24fe08435a6a1427de619892f2b28d1f
http://gyazo.com/4aa58fee549aba6771bcbc6811542f91
1 个解决方案
#1
You are probably looking at the wrong file. Your file will be located where your source code is. And not in the Debug
or Release
folder.
您可能正在查看错误的文件。您的文件将位于源代码所在的位置。而不是在Debug或Release文件夹中。
#1
You are probably looking at the wrong file. Your file will be located where your source code is. And not in the Debug
or Release
folder.
您可能正在查看错误的文件。您的文件将位于源代码所在的位置。而不是在Debug或Release文件夹中。