Error in compiling.. Graphics does not work

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 836 Views - Last Post: 04 October 2012 - 11:05 AM Rate Topic: -----

#1 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:08 AM

Please check the following code and suggest changes. Its a text editor program.
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <graphics.h>
#include <ctype.h>
#include <cstring.h>
#include <stdlib.h>
#include <stdio.h>
class edit
{
	private:
	int first_find (string str, string pattern)
	{
		size_t loc;
		loc = str.find(pattern);
		if(loc!=string::npos){cout<<"\n\t\t\t\tFound at "<< int(loc); return int(loc);}
		else {cout<<"\n\t\t\t\tNot there"; return -1;} 
	}
	int find_next(string str, string pattern)
	{
		size_t loc = first_find(str, pattern);
		loc = str.find(pattern,loc+1);
		if(loc!=string::npos){cout<<"\n\t\t\t\tFound at "<< int(loc);return int(loc);}
		else{cout<<"\n\t\t\t\tNot there"; return -1;}
	}
	void cut(string text)
	{
		gotoxy(23,20); cout<<"What do you want to cut?";
		string cutted;
		gotoxy(23,22); cout<<"Enter here: "cin>>cutted;
		do
		{
			replace_this(text, cutted, "", text.find(cutted));
		}while(text.find (cutted!=string::npos));
		goto(23,26); cout<<"Where do you want to paste?";
		int loc; goto(23,28); cout<<"Enter positin here: "; cin>>loc;
		do
		{
			replace_this(text, "", cutted, loc);
		}while(loc<=text.length());
	}
	void copy(string text)
	{
		gotoxy(23,20); cout<<"What do you want to copy?";
		string cutted;
		gotoxy(23,22); cout<<"Enter here: "cin>>cutted;
		goto(23,26); cout<<"Where do you want to paste?";
		int loc; goto(23,28); cout<<"Enter position here: "; cin>>loc;
		do
		{
			replace_this(text, "", cutted, loc);
		}while(loc<=text.length());		
	}
	int first_find(string str)
	{
		string pattern;  
		gotoxy(23,20); cout<<"Type the part you want to search for";
		gotoxy(23,22); cout<<"Enter here: "cin>>pattern;
		size_t loc;
		loc = str.find(pattern);
		if(loc!=string::npos){cout<<"\n\t\t\t\tFound at "<< int(loc);return int(loc);}
		else{cout<<"\n\t\t\t\tNot there"; return -1;}
	}
	int find_next(string str)
	{
		string pattern;
		gotoxy(23,20); cout<<"Type the part you want to search for";
		gotoxy(23,22); cout<<"Enter Here: "; cin>>pattern;
		size_t loc = first_find(str, pattern);
		loc = str.find(pattern,loc+1);
		if(loc!=string::npos){cout<<"\n\t\t\t\t\tFound at "<< int(loc);return int(loc);}
		else{cout<<"\n\t\t\t\tNot there"; return -1;}
	}	
	void replace_all(string str)
	{
		gotoxy(23,20); cout<<"To replace: "; string pattern; cin>>pattern; 
		gotoxy(23,22); cout<<"With: "; string replacement; cin>>replacement;
		size_t loc = first_find(str, pattern);
		while(loc!=-1)
		{
			str.replace(loc,pattern.length(),replacement);
			loc = find_next(str, pattern);
		}
	}
	void replace_this(string str, string pattern,  string replacement, int loc)
	{
		gotoxy(23,20);str.replace(loc,pattern.length(),replacement);	
	}
	public:
	int funda(char filename[80])
	{
		string text;
		ifstream t;
		t.open(filename);
		if(!t){cerr<<"\n\t\t\t\tNot found, Invalid"; menu::funda();}      
		t.seekg(0, std::ios::end);
		length = t.tellg();       
		t.seekg(0, std::ios::beg);
		text = new char[length];
		t.read(text, length);   
		t.close(); 
		int i;
		gotoxy(23,14); cout<<"Edit :" ;
		gotoxy(23,16); cout<<"1) Cut and Paste";
		gotoxy(23,18); cout<<"2) Copy and Paste";
		gotoxy(23,20); cout<<"3) Find";
		gotoxy(23,22); cout<<"4) Find Next";
		gotoxy(23,24); cout<<"5) Replace";
		gotoxy(23,26); cout<<"6) Replace All";
		gotoxy(23,28); cout<<"7) Back";
		gotoxy(18,32); cout<<"What would you like to open?? Enter the number";
		gotoxy(23,34); cout<<"Enter Here: [ ]";
		gotoxy(36,34);
		int choice;
		cin>>choice;
		while(choice!=1||choice!=2||choice!=3||choice!=4||choice!=5||choice!=6||choice!=7||choice!=8)
		{
			switch(choice)
			{
				case 1:clrscr(); cut(text); menu::save(filename, text); return 1; break;
				case 2:clrscr(); copy(text);  menu::save(filename, text); return 2; break;
				case 3:clrscr(); i = first_find(text);  menu::save(filename, text); return 4; break;
				case 4:clrscr(); i = find_next(text); menu::save(filename, text); return 5; break;
				case 5:clrscr(); replace_this(text); menu::save(filename, text); return 6; break;
				case 7:clrscr(); return 0; break;
				case 6:clrscr(); replace_all(text); menu::save(filename, text); return 7; break;
				default: gotoxy(18,36);
					 cout<<"Invalid choice, Press <enter>";
					 gotoxy(36,34);
			}
			cin>>choice;
		}

};
class file
{
	
	void create_file()
	{

    	int filecount=0;    
    	char file_no[33];
    	char untitled[]="Untitled";
    	char filename[80];
    	itoa(filecount++, file_no, 10);
    	strcpy(filename, untitled);
    	strcat(filename, file_no);
    	strcat(filename, ".txt");
    	ofstream file;
    	file.open(filename);
    	file.close();
    	cout<<"File successfully created";
	}
    void save()
	{
	    char nam[21];
	    cout<<"\n Enter a name for your file";
	    cin.getline(nam,21);
	    if(strcmp(nam,"") == 0)
	    ey h1("Untitled.txt");
	        h1.write();
	    	}
	    	else 
	    	{
	    	    hey h2(nam);
	    	    h2.write();
	    	}
	    ofstream output_file;
	    output_file.open((const char*)"C:\\Users\\Abhishek\\Desktop\\hello.txt");
	    char s[100];
    	input_file>>s;
    	cout<<s;
	}  
	public:
	void write()
    {
        ofstream file;
        file.open(filename,ios::out);
       	char reply;
       	do
       	{
       	    cout<<"\nEnter a line";
       	    char line[41];
       	    cin.getline(line,41);
       	    file << line << endl;
       	    cout<<"\nEnter again ?";
       	    cin >> reply;
       	    cin.get();
       	} while(reply=='y'||reply=='Y');
       	file.close();
    }
	private:
    int funda()
    {
	   	int i;
		gotoxy(23,14); cout<<"File :" ;
		gotoxy(23,16); cout<<"1) Create New File";
		gotoxy(23,18); cout<<"2) Save";
		gotoxy(23,20); cout<<"3) Close";
		gotoxy(23,22); cout<<"4) Back";
		gotoxy(18,26); cout<<"What would you like to open?? Enter the number";
		gotoxy(23,34); cout<<"Enter Here: [ ]";
		gotoxy(36,34);
		int choice;
		cin>>choice;
		while(choice!=1||choice!=2||choice!=3||choice!=4)
		{
			switch(choice)
			{
				case 1:clrscr(); create_file(); clrscr(); write(); return 1; break;
				case 2:clrscr(); save(); return 2; break;
				case 3:clrscr(); cout<<"\nThanks for using this, Press <enter>"; exit(9); return 4; break;
				case 4:clrscr(); return 0; break;
				default: gotoxy(18,36);
					 cout<<"Invalid choice, Press <enter>";
					 gotoxy(36,34);
		}
		cin>>choice;
		}
	}
};
class tools
{
	private:
	int length;
	void colour(string str)
	{
		int count = 0;
		gotoxy(23,14);cout<<"The various colours available are	: ";
		for(int i = 0; i<9; i++)
		{
			textcolor(i); gotoxy(23,14+2*i) cout<< i+1<< ") TEXT COLOR";
		}
		do
		{
			count++;
			if(count) cout<<"\n\t\t\t\tPlease enter correctly or this message will keep occurring";	
			gotoxy(23,14+2*i); cout<<"Select textcolor, Enter number: "; cin>>i;
		}while(i<10);
		textcolor(i-1);
		cout<<str;
	}
	void background(string str)
	{
		int count = 0;
		gotoxy(23,14);cout<<"The various Background colours available are: ";
		for(int i = 0; i<9; i++)
		{
			textcolor(i); gotoxy(23,14+2*i) cout<< i+1<< ") TEXT COLOR";
		}
		do
		{
			count++;
			if(count) cout<<"\n\t\t\t\tPlease enter correctly or this message will keep occurring";	
			gotoxy(23,14+2*(i+1)); cout<<"Select textcolor, Enter number: "; cin>>i;
		}while(i<11);
		textbackground(i-1);
		clrscr();
		cout<<str;
	}
	void font(string str)
	{
		gotoxy(23,14);cout<<"The various fonts available are: ";	
		for(int i = 0; i<=10; i++)
		{
			settextstyle(i,HORIZ_DIR,1);
			outtextxy(23, 14+25*(i+1), "Font" ));
			cout<<"\t no:"<<i+1;
		}
		cout<<"\n\t\tSelect a font number:"; cin>>i;
		settextstyle(i-1, HORIZ_DIR, 1);
		outtextxy(10,10, str);
	}
	public:
	int funda(char filename[80])
	{
		string text;
		ifstream t;
		t.open(filename);
		if(!t){cerr<<"\n\t\t\t\tNot found, Invalid"; menu::funda();}      
		t.seekg(0, std::ios::end);
		length = t.tellg();       
		t.seekg(0, std::ios::beg);
		text = new char[length];
		t.read(text, length);   
		t.close(); 
		gotoxy(23,14); cout<<"Tools :" ;
		gotoxy(23,16); cout<<"1) Font";
		gotoxy(23,18); cout<<"2) Colour";
		gotoxy(23,20); cout<<"3) Background Colour";
		gotoxy(23,22); cout<<"4) Back";
		gotoxy(18,32); cout<<"What would you like to open?? Enter the number";
		gotoxy(23,34); cout<<"Enter Here: [ ]";
		gotoxy(36,34);
		int choice;
		cin>>choice;
		while(choice!=1||choice!=2||choice!=3||choice!=4)
		{
			switch(choice)
			{
				case 1:clrscr(); font(text); menu::save(filename, text); return 1; break;
				case 2:clrscr(); colour(text); menu::save(filename, text); return 3; break;
				case 3:clrscr(); background(text); menu::save(filename, text); return 4; break;
				case 4:	return 0; break;
				default: gotoxy(18,36);
					 cout<<"Invalid choice, Press <enter>";
					 gotoxy(36,34);
			}
			cin>>choice;
		}
};
class view
{
	void v_open(char filename[80])
	{
		ifstream f;
		f.open(filename, ios::in);
		if(!f){cerr<<"\n\t\t\t\tError"; menu::funda();}
		char line[50];;
		f.getline(line,50);
		while(!f.eof())
		{
			cout<<line<<endl;
			file.getline(line,50);
		}
	}
	int funda(char filename[80])
	{
		ifstream t;
		t.open(filename);
		if(!t){cerr<<"\n\t\t\t\tNot found, Invalid"; menu::funda();}       
		t.close();
		gotoxy(23,14); cout<<"View :" ;
		gotoxy(23,16); cout<<"1) Open";
		gotoxy(23,18); cout<<"2) Back";
		gotoxy(18,32); cout<<"What would you like to open?? Enter the number";
		gotoxy(23,34); cout<<"Enter Here: [ ]";
		gotoxy(36,34);
		int choice;
		cin>>choice;
		while(choice!=1||choice!=2)
		{
			switch(choice)
			{
				case 1:clrscr(); v_open(filename); return 1; break;
				case 2:clrscr(); return 0; break;
				default: gotoxy(18,36);
					 cout<<"Invalid choice, Press <enter>";
					 gotoxy(36,34);
			}
			cin>>choice;
		}
	}	
};
class menu : protected edit, protected tools, protected view, protected file//help
{
	private:
	char filename[80];
	string str;
	int valid(char choice)
	{
		if(choice == 'f' || choice == 'e' || choice == 't' || choice =='h' || choice == 'v')
			return 1;
		else return 0;
	}
	public:
	void funda()
	{
		clrscr();
		gotoxy(2,2);
		cout<<"File  Edit  Tools  View  Help";
		gotoxy(23,20);
		cout<<"What would you like to do??";
		gotoxy(23,22);cout<<"Enter Here: [ ]";
		gotoxy(36,22);
		char choice;
		cin>>choice;
		tolower(choice);
		while(!valid(choice))
		{
			int i;
			switch(choice)
			{
				case "f": clrscr(); cout<<"\n\t\t\t\tEnter File name;" cin>>filename; i = file::funda(filename);
						    if(!i) choice = 'z';
						    break;
				case "e": clrscr(); cout<<"\n\t\t\t\tEnter File name;" cin>>filename;  i = edit::funda(filename);
						    if(!i) choice = 'z';
						    break;
				case "v": clrscr(); cout<<"\n\t\t\t\tEnter File name;" cin>>filename;  i = view::funda(filename);
						    if(!i) choice = 'z';
						    break;
				case "t": clrscr(); cout<<"\n\t\t\t\tEnter File name;" cin>>filename;  i = tools::funda(filename);
						    if(!i) choice = 'z';
						    break;
			    case "h": clrscr(); cout<<"\n\t\t\t\tEnter File name;" cin>>filename;  i = help::funda(str);
						    if(!i) choice = 'z';
						    break;
				default: gotoxy(20,24);
					 cout<<"Invalid entry, Press <Enter>, refer Help by typing H above";
					 cin.get();
			}
			gotoxy(36,22);
			cin>>choice;
		}
	}
	void save(char filename[80], string str)
	{
		ofstream f;
		f.open(filename,ios::out);
		if(!f){cerr<<"\n\t\t\t\tWrong"; funda();}
		f.write(str);
		file.close();
	}
};
void main()
{
	textbackground(WHITE);
	textcolor(BLACK);
	clrscr();
	menu m;	
	cout<<"\n\t\t\t\tWelcome to funda word processor. Please Press Enter";
	cin.get();
	m.funda();
	
}



Using Dev c++, tested using Turbo c++ compiler, It cannot recognise string

Is This A Good Question/Topic? 0
  • +

Replies To: Error in compiling.. Graphics does not work

#2 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:09 AM

Did you try including <string> without the .h? 'Coz std::string is defined in that class.
Was This Post Helpful? 0
  • +
  • -

#3 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:10 AM

I did. It doesn't work. Mine has to work with Turbo C++ where the ".h" has to be included.
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,025
  • Joined: 15-July 08

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:10 AM

Nobody is going to check through almost 500 lines of code simply to "check it". If you have specific problems, please tell us, so we can help you with them specifically.
Was This Post Helpful? 0
  • +
  • -

#5 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:11 AM

strings do not work
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon


Reputation: 4007
  • View blog
  • Posts: 12,361
  • Joined: 25-December 09

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:31 AM

This is part of the problem with trying to use a compiler that is older than the standard, things will be different. The string implementation provided by the Borland compiler is much different than the string implementation provided with modern standard compliant compilers.

Quote

Using Dev c++, tested using Turbo c++ compiler, It cannot recognise string

You need to decide which outdated compiler you are going to use. Dev C++ is almost but not quite as old as Turbo-C, but DevC++ is much more compliant to the C++ standards than is Turbo-C. So if you must use Turbo-C for your wonderful class then stick with it, don't try to convert a more modern code to an ancient dialect.

Now you say "strings do not work". You must tell us the exact problems you are having, and since you seem to be using two different compilers, what compiler you are using.

Jim

This post has been edited by jimblumberg: 04 October 2012 - 08:31 AM

Was This Post Helpful? 1
  • +
  • -

#7 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:32 AM

Well, that is not specific. Tell us what error messages you get.
Was This Post Helpful? 0
  • +
  • -

#8 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:38 AM

Ok, I'll give you the exact errors:
12: 'string' cannot start a parameter declaration
12: ) expected

Also,
149: Statement Missing ;
150: improper use of typedef 'file'
Same in 151
226: 'string' cannot start a parameter declaration
same in 243, 261,
355: 'edit' must be a previously defined class or struct
355 same for edit::tools
359: type name expected
359 declaration missing ;
407: ) expected
428: Declaration terminated incorrectly
Was This Post Helpful? 0
  • +
  • -

#9 jimblumberg  Icon User is offline

  • member icon


Reputation: 4007
  • View blog
  • Posts: 12,361
  • Joined: 25-December 09

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:39 AM

Okay, and what compiler do you happen to be using today?

And please post the complete error message, exactly as it appears in your development environment. These error messages contain important information to aid in locating and fixing the errors.


Jim
Was This Post Helpful? 0
  • +
  • -

#10 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:40 AM

Turbo C++
Was This Post Helpful? 0
  • +
  • -

#11 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:41 AM

Then forget std::string, since TC++ does not support it. Period.
Was This Post Helpful? 0
  • +
  • -

#12 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:41 AM

What else can I use for getting the whole line? char []?
Was This Post Helpful? 0
  • +
  • -

#13 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:43 AM

Yup, that's your best bet. Or, if you want, you can define your own string class, which will work like std::string.
Was This Post Helpful? 0
  • +
  • -

#14 booleanbalaji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 28-September 12

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:46 AM

Please tell me how to do that.
Was This Post Helpful? 0
  • +
  • -

#15 jimblumberg  Icon User is offline

  • member icon


Reputation: 4007
  • View blog
  • Posts: 12,361
  • Joined: 25-December 09

Re: Error in compiling.. Graphics does not work

Posted 04 October 2012 - 08:51 AM

Quote

Then forget std::string, since TC++ does not support it. Period.

Ah, but it does, sort of.

Lets look at these lines:

class file
{
...
    void save()
	{
	    char nam[21];
	    cout<<"\n Enter a name for your file";
	    cin.getline(nam,21);
	    if(strcmp(nam,"") == 0)
	    ey h1("Untitled.txt");
	        h1.write();
	    	}
	    	else 
	    	{
	    	    hey h2(nam);
	    	    h2.write();
	    	}
	    ofstream output_file;
	    output_file.open((const char*)"C:\\Users\\Abhishek\\Desktop\\hello.txt");
	    char s[100];
    	input_file>>s;
    	cout<<s;
	}  


And these lines of the above:
	    if(strcmp(nam,"") == 0)
	    ey h1("Untitled.txt");
	        h1.write();
	    	}
	    	else 



Please explain the above, it looks to be missing something!! Maybe you cut and pasted incorrectly.

Jim
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2