How to display a list in c++ [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am trying to print a list in C++.
My code is as follows:
void MovieFunctions::printMovieList(list<Movie> movies)
{
for (Movie m: movies)
{
cout << m << endl;
}
}
I am getting this error for the cout << m << endl line:
cannot convert 'm' (type 'Movie') to type 'const unsigned char*'
What's going wrong?

You need to implement the operator<<() (here) for this purpose.

Related

is cin is logic 1 or 0? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y;
while(cin)
cin>>x>>y;
cout<<"YES";
}
here for which input it will print out "YES"?
is cout is logic 1 or 0?
This will print "YES" for any input (except for an infinite stream of valid input, in which case it'll run forever and never print anything).
You forgot braces for your loop, so the cout statement is not actually in the loop.
Your cout is in no way conditional on the values you read in.

how void function can be return value? c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I do not understand, how void* function can be with return value. Code below, its work.
void *TcpClient::receive(int size=512)
{
char *buffer = new char[size];
if (recv(_sockfd , buffer , sizeof(buffer) , 0) < 0)
{
std::cerr << "recv failed";
}
return buffer;
}
The function returns void*, i.e. the pointer to memory, not void.

C++ how to print union name integer [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to print integer in C++:
int n5x = 1;
int n5y = 2;
[...]
int value = 5;
cerr << n+value+x << n+value+y << endl;
Is this possible in C++?
Thanks
As already mentioned, you cannot somehow "build" some string at run time and use it as variable name. This is a compile time mechanism, and even if this was a compile time problem, it would be a bad idea.
You most likely want
std::vector<int> nx(someLength);
std::vector<int> ny(someLenght);
int value = 5;
cerr << nx[value] << ny[value] << endl;
instead. (Or the same thing with std::array<int, someLength> nx{} if someLength is known at compile time and not big.)
cerr << n+value+x << n+value+y << endl;
Uhhm what please? You mean to expand symbol names and bind to them at runtime?
No that's not possible.
The closest thing you can get is setting up a std::map<std::string,int> and generate the key string values as needed.

if statement doesn't work with function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
void skaitoInformacija(){
ifstream duomenys("duom.txt");
int eil_nr;
duomenys >> eil_nr;
string eil[eil_nr];
string nereikalinga_eilute;
getline(duomenys, nereikalinga_eilute);
for(int i=0; i<eil_nr; i++){
getline(duomenys, eil[i]);
if(salinamTarpus(eil[i]) == "good"){ //this if statement doesn't work
}
}
}
void salinamTarpus(string eil) {
...
}
void salinamTarpus(string eil)
your function is not returning anything that you can compare with "good" string
you need to change it to return at least some result if you want to compare it...
string salinamTarpus(string eil) {
if(eil == "okString") // string eil is the right one
{
return "good";
}
return "bad";
}
also if your function salinamTarpus(string eil) returns only 2 values("good","bad") it might be better idea to return boolean,char or so. string is a little bit too much overkill

Threshoding image between certain range [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How to Threshold image between certain range?
i have done this but it doesn't work.
for (int i=0;i<s.size().height;i++)
{
for(int j=0;j<s.size().width;j++)
{
int k=int (s.at<uchar>(j,i));
if (k>6 && k<10)
k=255;
else k=0;
s.at<uchar>(j,i)=k;
}
}
You get an uchar value, and convert it to integer. Try this :
uchar k= s.at<uchar>(j,i);
if (k>6 && k<10) {
k=255;
}else {
k=0;
}
s.at<uchar>(j,i)=k;
I think it may work.