I am using Eclipse for C++ testing and I am getting an error related to the count_if() function.
Here is my code:
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> v{3,4,5,6,7,8,9,10,100,12,2};
auto isodd=[](int x){return x % 2;};
std::count_if(begin(v),end(v),isodd(3));
return 0;
}
While compiling this program Eclipse gives the following error: "function count_if() could not be resolved".
Thanks for any kind of hint.
I have done very silly mistake.By adding #include < algorithm>
I've solved my problem.
Related
#include <bits/stdc++.h>
using namespace std;
int32_t main()
{
cout << "Hello\n";
}
This is my code and the code is running, but Visual Studio Code shows this squiggles line with the message
expected initializer before 'std' gcc
which makes me conscious about my code.
Change int32_t to int
And never use #include <bits/stdc++.h>.
I am trying to define a function that requires me to make use of something called an "Associated Laguerre Polynomial". It's listed here under the library. In visual studio code, intellisense predicts "assoc_laguerre()" as a function so it clearly exists!
Yet, when building the code, it highlights the assoc_laguerre() function with the message: "Identifier not found".
Any help would be very appreciated!
Thanks!
Code:
#include <iostream>
#include <vector>
#include <string>
#include<vector>
#include<fstream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<time.h>
#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1
#include<math.h>
#include <stdio.h>
#include <cmath>
using namespace std;
//Function Definitons:
double a = 5.29177210903*pow(10,-11);
// Normalised Radial Component:
double Radial(double r,int n,int l,int Z){
double rho, prefactor,R,L,M;
rho = 2*r*Z/(n*a);
R=pow(pow(rho/r,3)*tgamma(n-l)/(2*n*tgamma(n+l+1)),0.5)*exp(-rho/2)*pow(rho,l);
L=R*assoc_laguerre(n-l-1,2*l+1,rho);
M=L*R;
return M;
}
int main()
{
vector<string> msg {"End Process."};
for (const string& word : msg)
{
cout << word << " ";
}
}
You're not compiling with the C++ 2017 version of the language standard enabled. Enable it, and this should be available. Your code compiles with GCC 10.1 and -std=c++17; but not if we use -std=c++14 instead.
GodBolt
I'm new to programming concepts and using my first time working with such software like Visual Studio. So now I'm learning C++ language.
When I trying to deal with error () function in C++ it gives me an error message saying "Unhandled exception at 0x76DE3E28 in ConsoleApplication3.exe: Microsoft C++ exception: std::runtime_error at memory location 0x0116F8CC.". Here is my code sample:
#include "stdafx.h"
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include <algorithm>
#include "std_lib_facilities.h"
using namespace std;
int area(int w , int l)
{
if (w <= 0 || l <= 0) error("There's something went wrong!");
return w / l;
}
int main()
{
int x = 3;
int y = 0;
cout << area(x, y) << endl;
keep_window_open();
}
I've checked it many times and didn't find anything wrong with the code. Is there anything that I did wrong with that code? Please help me with this guys. It's much appreciate!!
This is one of Bjarne Stroustrup's headers. If you looked at where the exception happened, you would see that an exception is being thrown. What you see is expected. You should not make assumptions about code you just get somewhere. Create your own error function and make it do what you are looking for.
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
cout<<"Just work";
return 0;
}
i dont why it is giving the error '::main' must return 'int'
I am giving the return type and value
IDE: Eclipde Mars
There is no error in your code. The return type of your main is int as it should be.
The static analyzer of eclipse cdt is not very good at parsing c++. If you don't like reading false positive error messages, then you should disable it.
I have been trying to debug this problem for a while and quite honestly, I just can't see what I'm doing wrong.
Why is there a syntax error?
#include <iostream>;
#include <time.h>;
#include <stdio.h>;
#include <stdlib.h>;
using namespace std;
class Problem3 {
public:
bool isPrime(long double num) {
srand(time(NULL));
return 0;
}
};
The error I'm getting is,
"Function 'srand' could not be resolved."
I'm well aware now that I don't need the semi-colons after 'include' statements
I'm using Eclipse CDT along with MinGW as my compiler
How I resolved the problem:
It had to do with the MinGW compiler I was using. Switching over to Visual Studio solved the problem.
; at the end of the #include directives are the problem in your code. #include directives don't need (wrong to place indeed) semicolons at the end unlike C++ statements.
[Warning] extra tokens at end of #include directive [enabled by default]
It seems any character after > in the directive causes this error/warning.
#include<iostream>a //error
Change to this:
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
class Problem3 {
public:
bool isPrime(long double num) {
srand(time(NULL));
return 0;
}
};
int main(){
cout<<"Hello Main";
}
EDIT:
Regarding the linker issue:
One suggestion is C++ expects types to be explicitly casted between types (more than C). So, use a cast to convert time_t which is returned by the time to unsigned int which is the input parameter type of srand. (And of course this might not be the problem with linker error)
Instead of using stdlib.h, try using <cstdlib>, try if it helps. Because it uses namespace.
Apart from that, I have seen this snippet here. Use that pattern if it helps.
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand(time(0)); //use current time as seed for random generator
int random_variable = rand();
cout << "Random value on [0 " << RAND_MAX << "]: "
<< random_variable << '\n';
}
there is already question in SO check if that helps Eclipse Method could not be resolved in a simple program C++
Never use time() to initialize srand()..
EDIT:
Now it seems many people got this kind of problem. I found a question How do I fix Eclipse CDT Error “Function 'isdigit' could not be resolved. He is facing the same problem. The asker suggested a work around to this in his question edit.
Quoted from that question:
I now believe this to be a Code Analysis problem. A better solution is
to edit the Code Analysis options to make "Function could not be
resolved" be a warning instead of an error. That way you can see the
warnings in Problems view, but continue to work. If the function is
REALLY missing, the compiler will tell you! I also have a new theory,
that the problem is with the Code Analyzer following symlinks, because
all of the "missing" functions are in symlinked include files. Would
love any input on this theory.
Hope that points to solve the problem.
; should not be there after #include.
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include files shoule not end with ;