首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

编程出现run_time error,该怎么处理

2013-09-25 
编程出现run_time error#include map#include vector#include iostream#include fstream#include

编程出现run_time error
#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 &in, const string &file) 

in.close(); // close in case it was already open 
in.clear(); // clear any existing errors 
// if the open fails, the stream will be in an invalid state 
in.open(file.c_str()); // open the file we were given 
return in; // condition state is good if open succeeded 


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");
    // read the transformation map and build the map 
    while (map_file >> key >> value) 
        trans_map.insert(make_pair(key, value));
{
    // ok: let's display it
    map<string, string>::iterator map_it = trans_map.begin();

    //cout << "Here is our transformation map: \n\n";
    while (map_it != trans_map.end()) {


        cout << "key: "   << map_it->first; 
        if (map_it->first.size() == 1)
            cout << "       ";
        if (map_it->first.size() == 3)
            cout << "     ";
        else if (map_it->first.size() == 4)
            cout << "    ";
        else if (map_it->first.size() == 5)
            cout << "   ";
        cout << "value: " << map_it->second << endl;
        ++map_it;
    }
    cout << "\n\n";

    {  // this block just produces the vector so that we can print it
       // for the book
    cout << "Here is our original string input:\n\n";
    // read some text to transform
    ifstream input;
    if (!open_file(input, argv[2]))
        throw runtime_error("no input file");
    string word;
    while (getline(input, word)) 
         cout << word << endl;
    cout << "\n\n\n";
    input.close(); input.clear();
    }
}

    // ok, now we're ready to do the transformations
    // open the input file and check that the open succeeded
    ifstream input;
    if (!open_file(input, argv[2]))
        throw runtime_error("no input file");

    string line;   // hold each line from the input



    // read the text to transform it a line at a time
    while (getline(input, line)) {
        istringstream stream(line);  // read the line a word at a time
        string word;
        bool firstword = true;  // controls whether a space is printed 
        while (stream >> word) {
           // ok: the actual mapwork, this part is the heart of the program
           map<string, string>::const_iterator map_it =
                               trans_map.find(word);

           // if this word is in the transformation map
           if (map_it != trans_map.end()) 
               // replace it by the transformation value in the map
               word = map_it->second;  
           if (firstword)
               firstword = false;
           else
               cout << " ";  // print space between words
           cout << word;
        }
        cout << endl;        // done with this line of input
    }
    return 0;
}



“slc.exe”: 已加载“C:\Users\Administrator\Documents\Visual Studio 2010\Projects\slc\Debug\slc.exe”,已加载符号。
“slc.exe”: 已加载“C:\Windows\System32\ntdll.dll”,Cannot find or open the PDB file


“slc.exe”: 已加载“C:\Windows\System32\kernel32.dll”,Cannot find or open the PDB file
“slc.exe”: 已加载“C:\Windows\System32\KernelBase.dll”,Cannot find or open the PDB file
“slc.exe”: 已加载“C:\Windows\System32\msvcp100d.dll”,已加载符号。
“slc.exe”: 已加载“C:\Windows\System32\msvcr100d.dll”,已加载符号。
slc.exe 中的 0x75a8c6e3 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0028f130 处的 std::runtime_error。
slc.exe 中的 0x75a8c6e3 处有未经处理的异常: Microsoft C++ 异常: 内存位置 0x0028f130 处的 std::runtime_error。
程序“[2336] slc.exe: 本机”已退出,返回值为 -529697949 (0xe06d7363)。


求编程高手相助。。。。。。
编程
[解决办法]
运行时传参数了吗?


if (argc != 3)
         throw runtime_error("wrong number of arguments");

[解决办法]
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。

判断是否越界访问,可以在数组的最后一个元素之后对应的地址处设置数据读写断点。如果该地址对应其它变量干扰判断,可将数组多声明一个元素,并设置数据读写断点在该多出元素对应的地址上。

[解决办法]
老赵,你就别忽悠人了,好不。

引用:
运行时传参数了吗?
C/C++ code?12if (argc != 3)         throw runtime_error("wrong number of arguments");


这位同学是正确的,你这个main函数是要引入 参数 的,你执行的时候,引入参数了么?估计你直接运行了,参数都没有写
[解决办法]
。。。。不是吧,main函数传递 参数 你不会?
http://zhidao.baidu.com/question/200069631.html

热点排行