This question already has answers here:
Why does VS not define the alternative tokens for logical operators?
(5 answers)
Closed 7 years ago.
I'm currently coding an app that will use OCR to read page numbers. I am using Visual Studio 2013 on a PC. I'm using C++ with OpenCV and Tesseract to complete this.
An error keeps on coming up and while I have come across similar problems, I can't find anything where it specific relates to the identifier 'and'. As such, I don't know how to fix this problem. Here is the section of code that it applies to:
vector<string> PgNrOCR::runRecognition(const vector<Mat> &pgnrImage, int pgnrType)
{
vector<string> output;
output.resize(pgnrImage.size());
for (size_t i = 0; i < pgnrImage.size(); i++)
{
if (!pgnrImage[i].empty() and pgnrType == 1)
output[i] = runPrediction1(pgnrImage[i], i);
if (!pgnrImage[i].empty() and pgnrType == 2)
output[i] = runPrediction2(pgnrImage[i], i);
}
return (output);
}
The 'and' identifiers in the if statement are bringing up the error, so I need to find an alternative solution. The full error appears as so.
Error 3 error C2146: syntax error : missing ')' before identifier 'and' c:\users\andrew\documents\visual studio 2013\projects\project1\project1\pgnrocr.cpp 152 1 PgTurn
I appreciate any help!
can you try && instead of and?
Related
include "stdafx.h"
#include <vector>
#include <iostream>
std::vector<int> biggest;
std::vector<int>vector1;
std::vector<int>vector2;
int main(){
biggest = [vector2[0],0]; //wrong initialization
for (int apply = 0; apply < (vector2.size()); apply++) {
if (biggest[0] < vector2[apply + 1]) {
biggest[0] = vector2[apply + 1];
biggest[1] = apply + 1;
}
}
Error C2065 'apply': undeclared identifier.why this error is occurring as i have already defined apply variable in for loop. error should be in initialization of biggest(vector).why wrong compiler code?
even intellisense is not giving me error is it a visual studio bug?
apply is in scope in the for loop body, so be assured, the error is not there. But you are aware that apply is out of scope after the loop body?
I'm only answering this because your use of
vector2.size() - 1
will give you hell if vector2 is empty, as the above will wrap around to a large unsigned value and your program will fail spectacularly! Use
for (int apply=0; apply + 1 < vector2.size(); apply++) {
instead.
I'm trying to add GA library (GALib) to my error-free program, when I add it, the compiler returns strange errors and repeat them so many times... For an example, "syntax error: missing '{' before '<' " is returned for the first line of the following template code:
template<class _Ty>
_Check_return_ inline _Ty _Pow_int(_Ty _Xx, int _Yx) _NOEXCEPT
{
unsigned int _Nx;
if (_Yx >= 0)
_Nx = static_cast<unsigned int>(_Yx);
else
_Nx = static_cast<unsigned int>(-_Yx);
for (_Ty _Zx = static_cast<_Ty>(1); ; _Xx *= _Xx)
{
if ((_Nx & 1) != 0)
_Zx *= _Xx;
if ((_Nx >>= 1) == 0)
return (_Yx < 0 ? static_cast<_Ty>(1) / _Zx : _Zx);
}
}
The error is in cmath.h
The error is repeated for the same line like for 25 times or so. The same for so many others. (The mentioned error is the first one on the list)
PS. I added the GA files using the following sequence:
1- Project properties>C++>Additional include libraries>select folder
2- Drag-Drop the folder containing the headers and sources to the project solution manager
PPS. All source files are with extension .C not .cpp
How can I solve such situation?
Following procedures in this page: msdn.microsoft.com/en-us/library/032xwy55.aspx Most errors just vanished (including the mentioned one).
The main problem was that the compiler deals with .C files with default option, which I changed to C++ as mentioned in aforementioned page.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
can someone point out the error in the following code . I am using a naive approach of comparing both strings character by charcter and updating variable 'u' then comparing it with length of substring . If this is true then variable 'c' is updated by one unit.
Program in C++ :
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s[50],a[20];
cin.getline(s,50);
cin.getline(a,20);
//int l=strlen(s);
int p=strlen(a);
int i,c=0,j,u=0,k;
for(i=0;s[i]!='\0';i++)
{
if(a[i]='\0')
{break;}
if(s[i]==a[0])
{
for(j=i,k=0;a[k]!='\0';j++,k++)
{
if(s[j]==a[k])
{
u++;
//continue;
}
//else
//break;
}
//cout<<endl<<u;
if(u==p)
{
c++;
}
}
u=0;
}
cout<<endl<<"count "<<c;
getch();
}
For any kind of input combination , I am getting output as 0.
The problem is with this part:
if (a[i] = '\0')
{
break;
}
First, you are using = instead of ==, but that is not the entire problem. Either change a[i] to s[i], or comment out the entire block. I don't see why it is needed.
My tip and my coding convention to avoid your bug that you use = instead of == in:
if(a[i]='\0')
is to put the rvalue in the left side of the operand and the lvalue in the right side, like this:
if ('\0' == a[i])
this convention will avoid bugs like that(you will get a compilation error):
if ('\0' = a[i])
this code will generate a compilation error:
Error C2106 '=': left operand must be l-value
This is my main code, I did search related mistakes before asking but it just doesn't seem wrong...The IDE says the error is in line 11.
#include<stdio.h>
int main()
{
float sal;
printf("Digite o salário bruto: ");
scanf("%f",&sal);
if(sal<=2246.75){
printf("Salário líquido : ",sal);
}
else{
if(sal>2246.75)&&(sal<2995.70){
printf("Salário Líquido: ",sal * 0.925);
}
else{
if(sal>2995.70)&&(sal<=3743.19){
printf("Salário Líquido: ",sal * 0.845);
}
else{
printf("Salário Líquido: ", sal * 0.775);
return 0;
}
}
}
}
if(sal>2246.75)&&(sal<2995.70){
The problem is that the entire condition must be placed within a set of parentheses.
It's fine if you want to further enclose the sub-conditions, but you must surround the entire lot, too:
if ((sal > 2246.75) && (sal < 2995.70)) {
Your if statement has to correct as follows, here you were missing bracket() for if.
if( (sal>2246.75)&& (sal<2995.70)){
You have to specify the formatter for printf correctly as follows; here you are missing type formatter.
printf("Salário Líquido: %f", sal * 0.775);
Both these errors are there in multiple occasions in your code.
there are actually two major kinds of problems with the posted code.
printf("Salário líquido : ",sal);
is missing a format specifier for the 'sal' variable
it should be:
printf("Salario liquido : %f", sal);
Note: each of the printf() statements have this same problem
if(sal>2246.75)&&(sal<2995.70){
is missing the outside parens
it should be:
if( (sal>2246.75) && (sal<2995.70) ) {
Note: I added some horizontal spacing for clarity only
the last two 'if' statements have this same problem
Suggest compiling with all warnings enabled.
For gcc, at a minimum, use '-Wall -Wextra -pedantic'
main always returns an 'int'
To avoid that return code being a random value, always end the function with:
return(0);
I think that if(sal>2246.75)&&(sal<2995.70) is supposed to be
if(sal>2246.75 && sal<2995.70).
I am getting these errors when I run my code in Dev-C++ 4.9.9.2 and yes, I'm a beginner
My program is a basic test program designed to give an int value on Left Shifts' Key Press.
In function int main()':
Do' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
;' before '{' token
'While' undeclared (first use this function)
;' before "on"
And here's my code:
using namespace std;
int main()
{
int on;
on = 1;
Do
{
GetASyncKeyState(VK_LSHIFT int key);
cout << key << endl;
}
While on = 1;
return 0;
}
Do/While should be do/while (i.e. lower case). It is a good idea to learn about/read the error and warning messages generated by the compiler.