vs里int main(int argc, char **argv)怎么用?

来源:百度知道 编辑:UC知道 时间:2024/05/27 06:26:38
#include <map>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
#include <sstream>
using std::map; using std::string; using std::vector;
using std::ifstream; using std::cout; using std::endl;
using std::getline; using std::make_pair;
using std::runtime_error; using std::istringstream;
ifstream& open_file(ifstream&, const string&);
int main(int argc, char **argv)
{
// map to hold the word transformation pairs:
// key is the word to look for in the input; value is word to use in the output
map<string, string> trans_map;
string key, value;
if (argc != 3)
throw runtime_error("wrong number of arguments");
// open transformation file and check that open succeeded
ifstream map_file;
if (!open_file(map_file, argv[1]))
throw runtime_error("no transformation file");

最前面的改成

#pragma warning(disable:4786)

#include <map>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
#include <sstream>
#include <iterator>
using namespace std;

又没有错误,又没有警告

编译通过 运行失败,原因可能有 1 变量未赋值使用,2类型使用不当。3溢出。
你切吧错误发来分析下。