【发布时间】:2017-09-13 05:31:32
【问题描述】:
我无法编译我的代码,因为它在第 16 行一直告诉我“错误:没有匹配的调用函数”。有什么建议吗?我想读取文件并将所有元音写入输出文件。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
string filename; // to hold the file name
ifstream inputfile; // input to a file
// Get the file name
cout << "Enter a file name: ";
cin >> filename;
// Open the file
inputfile.open(filename); // LINE 16
char vowel; // to store the vowels
ofstream outputfile; // to write to the file
// open file
outputfile.open("vowels_.txt");
while(inputfile.get(vowel)){
//If the char is a vowel or newline, write to output file.
if((vowel == 'a')||(vowel == 'A')||(vowel =='e')||(vowel =='E')||(vowel =='i')||(vowel =='I')||(vowel =='o')||(vowel =='O')||(vowel =='u')||(vowel =='U')||(vowel =='\n') && !inputfile.eof())
outputfile.put(vowel);
}
inputfile.close();
outputfile.close();
}
【问题讨论】:
-
第 17 行是空行。
-
@immibis 第 16 行,抱歉
-
我猜是 open() 调用。您需要传递一个字符指针,例如:
inputfile.open(filename.c_str()); -
或启用 C++11 或更高版本进行编译。
标签: c++ string function file-io compiler-errors