errors in system("cls")

hello everyone. i've got a problem System ("cls") doesn't work
i'm using Dev-C++ 5.2.0.0

what do you think is the problem here?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
#include<conio.h>
#include<stdio.h>

using namespace std;

main()

{
	
	char txt[30];
     int a, b;
	  system("cls");
	cout<<"\nEnter a phrase: ";
	gets(txt);
	
	for(a=0;txt[a]!='\0';a++)
	    cout<<txt[a];
	cout<<"\nIt has "<<a<<" characters.";
	cout<<"\nWhen reversed: ";
	
	for(b=a-1;b>=0;b--)
		cout<<txt[b];
	
		

	
	getch();
} 
If you compiled it exactly as is on your post you are missing int before main.

I did this on mine it compiled. I don't know if this is your question though but try this ?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>
#include<conio.h>
#include<stdio.h>

using namespace std;

 int main()
{
	
	char txt[30];
     int a, b;
	  system("cls");
	cout << "\nEnter a phrase: ";
	gets(txt);
	
	for(a=0;txt[a]!='\0';a++)
	    cout << txt[a];
	cout << "\nIt has "<<a<<" characters.";
	cout << "\nWhen reversed: ";
	
	for(b=a-1;b>=0;b--)
		cout << txt[b];
	
		

	
	system("pause");
return 0;
 
 }
So.. the question is why doesn't clearing the screen work before you've done anything on the screen?

Btw, if there's one input function you should never use, gets would be it.

[edit: You'll find the system declaration in <cstdlib> or <stdlib.h>]
Last edited on
Topic archived. No new replies allowed.