2014-02-03 3 views
0

Я пытаюсь сделать свою работу программы (отличной от предыдущей), и я все еще получаю ошибку компилятора/компоновщика, я понятия не имею, как исправить, может ли кто-нибудь помочь мне в некоторых решениях по исправлению компоновщика/компилятор или что-то еще?Ошибка компилятора/компоновщика

здесь журнал сборки им получать:

-------------- Build: Debug in lab1hwfinal (compiler: GNU GCC Compiler)--------------- 

mingw32-g++.exe -Wall -fexceptions -g -I..\Documents -c 
C:\Users\Dekkiller\Documents\lab1hwfinal\main.cpp -o obj\Debug\lab1hwfinal\main.o 
C:\Users\Dekkiller\Documents\lab1hwfinal\main.cpp: In function 'int main()': 
C:\Users\Dekkiller\Documents\lab1hwfinal\main.cpp:19:5: error: 'complexType' was not 
declared in this scope 
complexType sum; 
^ 
C:\Users\Dekkiller\Documents\lab1hwfinal\main.cpp:19:17: error: expected ';' before 
'sum' 
complexType sum; 
      ^
C:\Users\Dekkiller\Documents\lab1hwfinal\main.cpp:26:15: error: 'exit' was not declared 
in this scope 
    exit(1); 
     ^
C:\Users\Dekkiller\Documents\lab1hwfinal\main.cpp:45:38: error: 'atof' was not declared 
in this scope 
    realpart= atof(strone.c_str()); 
           ^
C:\Users\Dekkiller\Documents\lab1hwfinal\main.cpp:48:21: error: expected ';' before 
'outpobj' 
    complexType outpobj(realpart, imaginarypart); 
       ^
C:\Users\Dekkiller\Documents\lab1hwfinal\main.cpp:51:54: error: 'outpobj' was not 
declared in this scope 
    outputfile << "Object " << counter << "-" << outpobj << endl; 
               ^
Process terminated with status 1 (0 minute(s), 0 second(s)) 
6 error(s), 0 warning(s) (0 minute(s), 0 second(s)) 

Вот мой главный файл:

#include "Complex.h" 
#include <iostream> 
#include <fstream> 
#include <string> 
#include <sstream> 
using namespace std; 

int main() 
{ 
ofstream outputfile; 
ifstream inputfile; 
string str; 
double realpart; 
double imaginarypart; 
int symbol; 
char ch; 
string strone; 
string strtwo; 
complexType sum; 
int counter = 0; 

inputfile.open("complex.txt"); 
if(inputfile.fail()) 
{ 
    cout << "File opening failed." << endl; 
    exit(1); 
} 

outputfile.open("complexObj.txt"); 

inputfile >> str; 
while(inputfile) 
{ 
    symbol=str.find("+"); 
    ch = '+'; 
    if(symbol < 0) 
    { 
     symbol = str.find("-"); 
     ch = '-'; 
    } 
    stringstream streamin(str); 
    getline(streamin, strone, ch); 
    getline(streamin, strtwo, 'i'); 

    realpart= atof(strone.c_str()); 
    imaginarypart= atof(strtwo.c_str()); 

    complexType outpobj(realpart, imaginarypart); 
    counter++; 

    outputfile << "Object " << counter << "-" << outpobj << endl; 

    inputfile.close(); 
    outputfile.close(); 

    return 0; 
} 

} 

мой файл класса заголовок:

#ifndef COMPLEX_H 
#define COMPLEX_H 
#include <iostream> 


class complexType 
{ 
friend std::ostream& operator<<(std::ostream& os, const complexType& obj); 
public: 
    complexType(); 
    complexType(double r, double i); 
    complexType operator+(const complexType& objtwo); 
private: 
    double real; 
    double imagine; 
}; 

#endif // COMPLEX_H 

вот мой файл класса каст :

#include "Complex.h" 
#include <iostream> 
using namespace std; 


complexType::complexType() 
{ 
real=0; 
imagine=0; 
} 

complexType::complexType(double r, double i) 
{ 
real=r; 
imagine=i; 
} 

ostream& operator<<(ostream& os, const complexType& obj) 
{ 
os << obj.real << "," << obj.imagine; 
return os; 
} 

complexType complexType::operator+(const complexType& objtwo) 
{ 
complexType sum; 
sum.real = real + objtwo.real; 
sum.imagine = imagine + objtwo.imagine; 
return sum; 
} 

Прошу прощения за такие подобные вопросы, но я не могу понять, что не так с моим компоновщиком или компилятором.

+0

Какой у вас компилятор? Являются ли файлы в одном каталоге? Названы ли они «Complex.h» и «Complex.cpp»? –

+0

Привет, я использую GNU GCC Compileron для выбранного компилятора, я считаю, что компилятор, который пришел с моей установкой кодовых блоков, был MinGW. – user3264198

+0

Убедитесь, что ваши файлы 'Complex.h' и' Complex.cpp' находятся в том же каталоге, что и ваш основной файл, или в папке 'Documents', на которую вы ссылаетесь, с аргументом' -I'. (Хотя, если они находятся в «Документах», вам нужно будет что-то явно связать в «Complex.o» в командной строке. Самый простой - просто поместить все файлы в одну и ту же папку). – Turix

ответ

Смежные вопросы