调试后项目加载错误

时间:2013-07-24 03:24:19

标签: c++

编辑:所以接受了你们的建议,现在我的程序编译了。但现在我无法让它运行,因为我得到了这些错误。

'baseconverter.exe': Loaded 'C:\Users\OwnerT\Documents\Visual Studio 2010
\Projects\baseconverter\Debug\baseconverter.exe', Symbols loaded.
'baseconverter.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'baseconverter.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'baseconverter.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'baseconverter.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.
'baseconverter.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
The program '[5320] baseconverter.exe: Native' has exited with code 0 (0x0).

这是新的更新代码。我修复了std :: cout并删除了名称空间,但我认为这会使编码过载。

converter.h

#ifndef CONVERTER_H
#define CONVERTER_H
using std::cout;
using std::cin;
using std::endl;
//This contains the function types needed for
//reading an input
//converting from any base to base10
//convert from base10 to any base
extern int non10num;
extern int bIn;
extern int bOut;
extern int b10num;
extern int Conv;
extern int option;
extern int sum;
extern int num;

#endif   

convertion.cpp

#include <iostream>
#include <cmath>
#include <string>
#include <cctype>
#include "converter.h"

using std::cout;
using std::cin;
using std::endl;

int non10num = 0;
int bIn      = 0;
int bOut     = 0;
int b10num   = 0;
int Conv     = 0;
int option   = 0;
int sum      = 0;
int num      = 0;
int main ()
{

//Reinstates the int variables

int pow = 1; 
while (option)
{
sum += b10num * pow;
num /= 10;
pow *= non10num;
}
}

converter.cpp

#include <iostream>
#include <cmath>
#include <string>
#include <cctype>
#include "converter.h"

using std::cout;
using std::cin;
using std::endl;

extern int non10num;
extern int bIn;
extern int bOut;
extern int b10num;
extern int Conv;
extern int option;
extern int sum;
extern int num;


//This brings us to the menu
void menu()
{
cout << "1. Base to Base" << endl;
cout << "2. Base to Base-10" << endl;
cout << "3. Base-10 to Base" << endl;
cout << "4. Exit" << endl;
cout << "" << endl;
cout << "Choose your option: ";
        cin >> option;
        switch (option)
        {
        case 1: cout << "Enter your integer: "; //Asks for user input
                    cin >> non10num;
                cout << "Enter which base it belongs to: ";
                    cin >> bIn;
                cout << "Enter the base it should be converter: ";
                    cin >> bOut;

                cout << non10num << " in base " << bIn << " is " << non10num%bIn << " in base " << bOut<< endl; //Converts the data
                break;

        case 2: cout << "Enter your integer: ";
                    cin >> non10num;
                cout << "Enter which base it belongs to: ";
                    cin >> bIn;
                cout << non10num << " in base " << bIn << " is " << non10num%10 << " in " << b10num;
                break;

        case 3: cout << "Enter your integer: ";
                    cin >> b10num;
                cout << "Enter which base the integer will be converted: "; cin >> Conv;

                cout << b10num << " in base 10 is " << b10num%10  << " in "<< Conv;
                break;

        case 4: //Exits the menu
            return ;
            break;
            default: 
            cout << "You have entered an invalid option!" << endl;
        }

while (option!=0);
return ;
}

2 个答案:

答案 0 :(得分:1)

在cpp文件的一个中定义这样的每个:

int bIn = 0;

然后在所有其他人中声明这样:

extern int bIn;

目前的情况是,你违反了One Definition Rule。

另外,现在,您在main()中声明了相同名称的变量,这些变量将隐藏该函数中的所有全局变量,这可能不是您想要的。

答案 1 :(得分:0)

不要在任何文件中#include "convertion.cpp"。通过包含它,您将替换包含文件内容的行,因此您在同一程序中声明了non10num两次:一次在“converter.cpp”中(因为包含行)和一次在“ convertion.cpp”。我希望这会有所帮助。