错误:一个无法解析的外部命令
他过江 2016-07-22 11:58:48 #include<iostream>
#include<map>
#include<string>
#include<fstream>
#include<sstream>
#include<algorithm>
using namespace std;
map<string, string> rule(ifstream &rule_file);
const string &output(const string &s, map<string, string> &m);
void Transform(ifstream &rule_file, ifstream &source_file)
{
auto trans_rule = rule(rule_file);
string line;
while (getline(source_file, line))
{
istringstream in(line);
string word;
bool firstword = true;
while (in >> word)
{
if (firstword)
firstword = false;
else
cout << " ";
cout << output(word, trans_rule);
}
cout << endl;
}
}
map<string, string> rule(ifstream &rule_file)
{
map<string, string> m;
string word, expression;
while (rule_file >> word && getline(rule_file, expression))
if (expression.size() > 1)
m[word] = expression.substr(1);
else
throw runtime_error("no rule for " + word);
return m;
}
const string &output(const string &s, const map<string, string> &m)
{
auto map_it = m.find(s);
if (map_it != m.cend())
return map_it->second;
else
return s;
}
int main(int argc, char *argv[])
{
ifstream in(argv[2]);
ifstream ru(argv[1]);
if (!ru)
{
cerr << "file1 open error" << endl;
system("pause");
exit(-1);
}
if (!in)
{
cerr << "file2 open error" << endl;
system("pause");
exit(-1);
}
in.close();
ru.close();
Transform(ru, in);
system("pause");
return 0;
}
为什么我把rule函数和output函数提前声明就有错,而两个函数的函数体放在调用它们的Transform函数之前就可以?