compile error in C++ code

compileerror

#1

Why is it showing this error:
prog.cpp: In function ‘int main()’:
prog.cpp:6: error: ‘cin’ was not declared in this scope
prog.cpp:9: error: ‘cout’ was not declared in this scope

How can I remove it…Please help…


#2

Try using std::cout and std::cin


#3

Few things:

1)Instead of doing std:: every time, put a using namespace std; statement after header files.

  1. When using cin do cin>>x; and cin>>y;

  2. For cout do cout<<y and…

I checked your code. There is a slight mistake in your logic which is giving you WA. Hint: Consider the case x=10 and y=10.20!!


#4

Add " using namespace std;" after the header files , to remove the error .


#5

but i used using namespace std;
still there is the same error in my program

#include<iostream>
#include<string>
using namespace std;
int main()
{
int n,i,j,k,x,y;
char a[10][10],b[10][10],l[10];
cout<<"enter the no. of text";
cin>>n;
for (i=0;i<n;i++)
{
gets(a*);
l*=strlen(a*);
}

for (i=0;i<n;i++)
	{for (j=0;j<l*;j++)
		{for(k=0;k<j;k++)
			{if(a*[j]==a*[k])
				{
				for(x=j;x<l*-1;x++)
				a*[x]=a*[x+1];
				a*[x]=' ';
				j--;
				l*--;
				}
			}
		}
	puts(a*);
	}
}

the error is coming as :
prog.cpp: In function ‘int main()’:
prog.cpp:13: error: ‘strlen’ was not declared in this scope


#6

@aks1997: Because, you’ve not declared the header files required for the same. See, take a look at your own code which successfully compiles: http://ideone.com/4EWXA4 or alternatively you could use only #include <bits/stdc++.h> to avoid confusion if you don’t know which header file you’re looking for. Look here for its sample implementation: http://ideone.com/5aNH6P


#7

include header files…
#include
using namespace std;


#8

#include
using namespace std;
int main()
{
int t,i,a[100];

int j=1,f=1;
cout<<"enter the no. of values you want to enter"<<endl;
cin>>t;
if(t<=100){

cout<<"enter the values in list"<<endl;
for(i=0;i<t;i++)
cin>>a*;

for(i=0;i<t;i++)
{
  while(j<=a*)
  {
  	 f=f*j;
  	 j++;
  }
  cout<<"

the factorial of given no. is"<<endl<<f;
}
}}

why i am getting wrong answer?


#9

oh!!!
Thanks a lot kcahdog…:slight_smile: