You are not logged in. Please login at www.codechef.com to post your questions!

×

compile error in C++ code

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..

asked 26 May '14, 22:00

jyoti14's gravatar image

0★jyoti14
112
accept rate: 0%


Try using std::cout and std::cin

link

answered 26 May '14, 22:07

jawad's gravatar image

4★jawad
603
accept rate: 0%

Few things:

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

2) When using cin do cin>>x; and cin>>y;

3) 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!!

link

answered 26 May '14, 22:23

kcahdog's gravatar image

3★kcahdog
10.0k2854129
accept rate: 14%

oh!!! Thanks a lot kcahdog....:)

(27 May '14, 13:36) jyoti140★

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

link

answered 27 May '14, 13:59

the65bit's gravatar image

4★the65bit
1.1k101328
accept rate: 13%

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[i]);
l[i]=strlen(a[i]);
}

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

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

link

answered 10 Nov '14, 16:47

aks1997's gravatar image

2★aks1997
1
accept rate: 0%

edited 11 Nov '14, 11:23

tech_boy's gravatar image

2★tech_boy
1.2k41931

@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

link

answered 12 Nov '14, 15:44

belowthebelt's gravatar image

2★belowthebelt
312
accept rate: 0%

edited 12 Nov '14, 15:45

include header files.. #include<iostream> using namespace std;

link

answered 12 Nov '14, 16:03

mt36056's gravatar image

0★mt36056
1
accept rate: 0%

edited 12 Nov '14, 16:03

include<iostream>

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[i];

for(i=0;i<t;i++)
{
  while(j<=a[i])
  {
     f=f*j;
     j++;
  }
  cout<<"\nthe factorial of given no. is"<<endl<<f;

} }}

why i am getting wrong answer?

link

answered 24 Oct '15, 21:07

apoorv_jain95's gravatar image

0★apoorv_jain95
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×34

question asked: 26 May '14, 22:00

question was seen: 9,260 times

last updated: 24 Oct '15, 21:07