Firstly.. I am using codeblocks! I tried to put the functions in cpp files... but I get huge number of errors heres my program when the files are transfered into .cpp file, my new files are like this
main
Code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include "Window_mgr.h"
int main()
{
Screen::pos ht=24,wd=10;
Screen scr(24,10,' ');
Screen *p=&scr;
char c=scr.get();
c=p->get();
}
Screen
Code:
#ifndef SCREEN_H_INCLUDED
#define SCREEN_H_INCLUDED
#include <iostream>
class Screen{
friend ostream& storeOn(std::ostream&,Screen&);
friend class Window_mgr;
friend void showscreen(const Screen&);
friend istream &read(istream&,Screen&);
public:
typedef string::size_type pos;
Screen()=default;
Screen(pos ht,pos wd,char c):height(ht),width(wd),contents(ht*wd,c){}
char get() const {return contents[cursor];}
inline char get(pos ht,pos wd) const;
Screen &move(pos r,pos c);
void some_member() const;
Screen &set(char);
Screen &set(pos,pos,char);
pos size() const;
private:
mutable size_t access_ctr;
pos cursor=0;
pos height=0,width=0;
string contents;
};
#endif // SCREEN_H_INCLUDED
Window_mgr
Code:
#ifndef WINDOW_MGR_H_INCLUDED
#define WINDOW_MGR_H_INCLUDED
#include <iostream>
#include "Screen.h"
#include <vector>
struct Window_mgr{
public:
using ScreenIndex=std::vector<Screen>::size_type;
void clear(ScreenIndex);
ScreenIndex addScreen(const Screen&);
private:
std::vector<Screen> screens{Screen(24,80,' ')};
};
void Window_mgr::clear(ScreenIndex i)
{
Screen &s=screens[i];
s.contents=string(s.width*s.height,' ');
}
Window_mgr::ScreenIndex Window_mgr::addScreen(const Screen &s)
{
screens.push_back(s);
return screens.size()-1;
}
#endif // WINDOW_MGR_H_INCLUDED
and the functions of Screen in
Code:
Screen::pos Screen::size() const
{
return height*width;
}
inline
Screen &Screen::move(pos r,pos c)
{
pos row=r*width;
cursor =row+c;
return *this;
}
char Screen::get(pos r,pos c) const
{
pos row=width*r;
return contents[row+c];
}
void Screen::some_member() const
{
++access_ctr;
}
void showscreen(const Screen &in)
{
for(unsigned i=0;i<in.height*in.width;++i)
{
if(i&&i%in.width==0) cout<<endl;
cout<<in.contents[i];
}
cout<<endl;
}
istream &read(istream &is,Screen &in)
{
cout<<"Enter the height,width and character of the screen seperated by space "<<endl;
is>>in.height>>in.width;
char c=getwchar();
string s(in.height*in.width,c);
in.contents=s;
return is;
}
inline Screen &Screen::set(char c)
{
contents[cursor]=c;
return *this;
}
inline Screen &Screen::set(pos r,pos col,char c)
{
contents[r*width+col]=c;
return *this;
}
This program gives several error Including ostream doesnt name a type,Istream doesnt name a type , string doesnt name a type etc etc.. and
Always copy and paste the errors you are getting here.
how to copy paste errors in code blocks?? When I right click on the error button theres no options such as copy..