Witam. Pisze sobie taki tam program który otworzy plik kiedy będzie potrzeba i zamknie jak skończy.Mam taki kod(patrz niżej), i wyskakują mi dwa błędy w funkcji 'main'
Line: | Massage:
8 | Undefined reference to 'fileOP::write(std::string)'
9 | Undefined reference to 'fileOP::show()'
co jest źle w tym kodzie i co tu zmienić?
(C++ uczę się od niedawna)
main.cpp:
#include "fileop.h"
// C:\Users\Admin\Desktop\sdl cos\pliki\bin\Debug\baza.txt
int main()
{
fileOP test;
string tekst;
getline(cin,tekst);
test.write(tekst); //ma zapisać tekst pobrany linijkę wyżej -- tu jest linia 8
test.show(); //ma pokazać to co zapisał -- a tu 9
return 0;
}
fileop.h:
#include <iostream>
#include <fstream>
#include <conio.h>
#include <stdlib.h>
#include <string>
using namespace std;
fstream map;
class fileOP
{
public:
int open();
int close();
int write(string tekst);
int show();
};
int open()
{
map.open( "C:\\Users\\Admin\\Desktop\\sdl cos\\pliki\\bin\\Debug\\baza.txt", ios::in | ios::out | ios::binary);
if(!map.good()){cout<<"error";}
return 0;
}
int close()
{
map.close();
return 0;
}
int write(string tekst)
{
open();
map.write( & tekst[ 0 ], tekst.length() ); //zapisuje dane poczynając od 0 indeksu
close();
return 0;
}
int show()
{
char bufor[1024];
open();
map.read( bufor, 1024 ); //wczytuje tyle danych ile się zmieści do bufora
cout << "Wczytano " << map.gcount() << " bajtów do bufora" << endl;
for(int i=0;i<map.gcount();i++)
{
cout<<bufor[i];
}
close();
return 0;
}