cout was not declared in this scope [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm new to C++ and coding entirely.
When I try to build my code it gives me "error: 'count' was not declared in this scope"
Everything I look up either tells me to add "using namespace std;" or add "int main()" but neither works for me.
#include <iostream>
using namespace std;
main()
{
int A = 4;
count << &A;
}

There is a typo in your identifier.
count should be cout.
Also, main should have the return type of int as it isn't standard C++ to automatically deduce the return type as int if not specified. In short, int main() is required.

Related

error: no match for ‘operator[]’ (operand types are ‘std::map<std::__cxx11::basic_string<char>, int>’ and ‘char’) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I wanted to test if the increment ++ works for the std::map :
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<string, int> map;;
map['1'] = 0;
map['1']++;
cout << map['1'] << endl;
return 0;
}
And Ì get the error of the title for :
map['1'] = 0;
I do not understand why
In C++ '1' is a character, not a string literal, and your map has a key std::string, which is not same types. That is why the std::map::operator[] gave you the compiler error, it is mismatch type.
You need "" for mentioning it is a string literal.
map["1"] = 0;
Also, have a read:
Why is "using namespace std;" considered bad practice?
Why should I not #include <bits/stdc++.h>?

In C++, why can int initialize a variable using new operator but double cannot? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
#include <iostream>
using namespace std;
int main()
{
int* i = new int(75);
double* d = new double(3.14159);
printf("%d\n",*i);
printf("%d\n",*d);
}
In the above code i returns a value of 75 however, d returns 1.
I tried explicitly initializing it as
*d = 3.14159
But the value is still returned as 1.
Can anyone explain what I am doing wrong here?
Use this for printing.
cout<<*i;
cout<<*d
"%f" is the (or at least one) correct format for a double if you want to use printf for printing the value of the double in C++.

Why is this string not declared in the scope? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm experimenting with classes and I'm wondering why I'm getting an error saying "calvin" is not defined in the scope. Thanks.
#include <iostream>
#include <string>
using namespace std;
class people
{
public:
string name;
int age;
};
int main()
{
people peeps[10];
peeps[1].name = calvin;
peeps[1].age = 21;
cout << peeps[1].name << peeps[1].age;
}
Without quotes, calvin is a variable (which is undefined). You should make it a literal (i.e. "calvin").
firstly i would suggest if you had made and age private class members and also create get name/age and set name/age member functions to protect your data and finally
peeps[1].name = calvin;
//calvin is an undefined variable
you should have used string literals for example
peeps[1].name = "calvin";

error: 'listOfColors' was not declared in this scope [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm new to C++ and I don't understand why I'm getting a not declared error on this:
int main(){
string listOfColors[5] = {"red","blue","green","yellow","magenta"};
for(int i = 0;i < sizeof listofColors;i++){
cout << listofColors[i] << "\n";
}
return 0;
}
This is my first utilization of an array so far, so I may just not be declaring it correctly. I also had the array declaration before the main function beforehand.
You declared your variable as listOfColors (capital "O"), and then you use it as listofColors in your for loop. All you need to do is to capitalize the "O" when using your variable.

Returning boolean value does not print anything and doesn't show any compiler errors [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This is a function to check a number for a power of two. Although the compiler does not print anything, it's also not showing any errors. Please let me know if the logic is correct or not.
Here is my code:
#include <bits/stdc++.h>
using namespace std;
bool isPowerofTwo(long long n)
{
// Your code here
for (int i = 1; i <=n; i<<1)
{
if(i==n){
return true;
}
}
return false;
}
int main()
{
cout << isPowerofTwo(2);
return 0;
}
The expression i<<1 in the third statement (the "iteration expression") of your for loop doesn't actually do anything (that is, it doesn't modify the value of i). You need, instead, i<<=1 (or, in 'long form', i = i << 1).
Also, please read: Why should I not #include <bits/stdc++.h>?. In your code, the only standard header you need is #include <iostream>. Another good post to read is: Why is "using namespace std;" considered bad practice?.