【发布时间】:2012-02-24 11:43:22
【问题描述】:
我可以指定我想在 C++ 中写入的文件吗?我希望能够输入文件名并写入该文件。当我尝试制作myfile.open("example.txt") myfile.open(var) 时,我得到了一个很大的错误......
错误:没有匹配函数调用“std::basic_ofstream >::open(std::string&)” /usr/include/c++/4.2.1/fstream:650:注意:候选人是: void std::basic_ofstream<_chart _traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits]
你能理解这一点或解释我做错了什么吗?我觉得这很简单,因为这是我使用 C++ 的第一周。
【问题讨论】:
-
一般来说,您希望发布问题的最小工作示例,否则人们只能猜测细节。帮助人们帮助你。
-
@luke 我做了,那是
myfile.open("example.txt")。 -
这并没有告诉我们
myfile被声明为什么,也不是产生错误的行。可以这样想:您想向我们展示您的程序的最短版本,以证明您遇到的确切问题。
标签: c++ file-io compiler-errors