EDIT: Thanks to some help, I see that I was just missing parentheses. Problem solved.
Recently Visual Studio has been giving me errors on the simplest things that are not actually wrong, and because of this I cannot run any program, and it is very frustrating. I have Visual Studio Professional 2013 with Update 5, running on Windows 10. Let me give an example.
When I write the program:
#include <iostream>
using namespace std;
int main
{
cout << "Hello World!" << endl;
return 0;
}
I get the errors:
main.cpp(6): error C2143: syntax error : missing '}' before ';'
main.cpp(8): error C2059: syntax error : 'return'
main.cpp(9): error C2059: syntax error : '}'
main.cpp(9): error C2143: syntax error : missing ';' before '}'
Also, on cout, IntelliSense gives me the error "no suitable conversion function from 'std::basic_ostream...' to 'int' exists". And on return it says "error: expected a declaration." That same error is also given on the final bracket.
Why am I getting all of these nonsense errors and how to I make them stop appearing so I can run a program?
(P.S. I have tried writing the program with and without "using namespace std" and nothing changes.)
You're missing parenetheses from main:
#include <iostream>
using namespace std;
int main()
^^
{
cout << "Hello World!" << endl;
return 0;
}
Related
I have the following code:
#include "wx\wx.h"
class BClient : public wxApp
{
virtual bool OnInit();
virtual int OnQuit();
};
IMPLEMENT_APP(BClient)
bool BClient::OnInit()
{
return true;
}
int BClient::OnQuit()
{
return 0;
}
As soon I try to add the line
#include <thread>
I receive this errors:
Error 10 error C2347: '__w64' : can not be used with type '__w64
unsigned __int64'
Error 12 error C2143: syntax error : missing ';' before ','
Error 13 error C2059: syntax error : ','
The errors refer to this file: c:\program files (x86)\microsoft visual studio 12.0\vc\include\concrt.h
So, for some reason, wxwidgets and std::thread doesn't mix together.
Can someone explain to me why this is happening and is there a workaround for this issue ?
Thanks.
Something is wrong with your MSVS installation. Here, adding #include <thread> line either before or after #include <wx/wx.h> one works without any problems.
Also, on a completely unrelated note, there is no OnQuit() in the base class, only OnExit().
I have the following piece of C++ code which compiles without problem:
namespace namespace_top_of_FDD{
int int_systemReturn=system("pause | echo scope: namespace_top_of_FDD");
FDD*FDD_Ptr_Object=NULL;
//if(true){}
}
But when I add if statement, like the following, I get the following error massages, I'm wondering why.
namespace namespace_top_of_FDD{
int int_systemReturn=system("pause | echo scope: namespace_top_of_FDD");
FDD*FDD_Ptr_Object=NULL;
if(true){}
}
Error messages (when I use if statement):
1>.\FDD.cpp(6) : error C2059: syntax error : 'if'
1>.\FDD.cpp(6) : error C2143: syntax error : missing ';' before '{'
1>.\FDD.cpp(6) : error C2447: '{' : missing function header (old-style formal list?)
Code in namespaces may contain only declarations and/or definitions (which in turn are declarations). You may not place executable statements similar to the if statement.
Visual Studio (2012/C++) is reporting multiple errors all relaxing to errors in syntax when I cannot see any errors.
I'm calling the function with Ping(ID); and ID is a string (Already defined), I've defined the function in the relevant header file as
#include <string>
int Ping(string ID);.
A stripped down version of the function is
int Ping(string ID)
{
// Ping
cout<<"Pinging\n";
cout<<ID;
return (1);
}
and the errors in the header file are as follows;
Error 3 error C2059: syntax error : ')' func.h 3 1
Error 1 error C2065: 'string' : undeclared identifier func.h 3 1
Error 2 error C2146: syntax error : missing ')' before identifier 'ID' func.h 3 1
I'm really stuck with what I need to do to fix this, so any guidance on how to fix it will be greatly appreciated.
You did not qualify the name with std::, as std::string.
As the title says, I'm getting a compiler error in a VS2008 C++ program. I'm not sure how better to describe my problem than in code. The following compiles unless I uncomment the TEST line.
#include <windows.h>
#include <iostream>
using namespace std;
//#define TEST //<-- uncomment for error
#ifdef TEST
void test(void* interface)
{
return;
}
#endif
int main()
{
cout << "Hello World" << endl;
system("PAUSE");
return(0);
}
When uncommented I get the following errors:
1>main.cpp(7) : error C2332: 'struct' : missing tag name
1>main.cpp(7) : error C2144: syntax error : '<unnamed-tag>' should be preceded by ')'
1>main.cpp(7) : error C2144: syntax error : '<unnamed-tag>' should be preceded by ';'
1>main.cpp(7) : error C2059: syntax error : ')'
1>main.cpp(8) : warning C4094: untagged 'struct' declared no symbols
1>main.cpp(8) : error C2143: syntax error : missing ';' before '{'
1>main.cpp(8) : error C2447: '{' : missing function header (old-style formal list?)
This is unmanaged code, so I'm not sure what the issue with the word interface is. Is there any way to get this code to compile as is, or do I have to change every instance of the term interface to something else?
Thanks!
If your code needs to include Windows.h then you should avoid using the name interface as it's reserved for the use that the Windows SDK has reserved for it (essentially it's a synonym for the keyword struct). There are probably hacks to work around that problem (you could #undef interface after including the SDK headers), but you should probably avoid using that identifier.
The word interface is reserved by MSVC++, as it is a non-standard keyword added by Microsoft Compiler, which is used to define interface in MSVC++.
So use a different name for the parameter, something like this:
#ifdef TEST
void test(void* test_interface)
{
return;
}
#endif
I have a problem: My codes work well in CentOS g++, but when I compile them in visual studio 2008, the visual studio tells me errors like below:
1.c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) : error C2144: syntax error : '__w64 unsigned int' should be preceded by '}'
2.error C2143: syntax error : missing '}' before 'namespace'.
My file coding is UTF-8. Should I change them in Unicode all, I change some error file in Unicode,it still has errors like above.
below are some sourecode:
#ifndef ENRC_CODE_DEFS_H
#define ENRC_CODE_DEFS_H
enum ENReturnCode
{
ENRC_SUCCESS = 0,
ENRC_FAILED,
ENRC_NODATA,
ENRC_CONFIG_NOT_AVAILABLE,
ENRC_INVALID_SUBSCRIBE_ID,
ENRC_INVALID_SUBSCRIBE_CONDITION,
ENRC_INVALID_SUBSCRIBER,
ENRC_INVALID_PARAMETER,
ENRC_THREAD_RUNNING,
ENRC_SUBSCRIBE_LIST_EMPTY,
ENRC_OUT_OF_MEMORY // 10
}
e:\my_code\cppcommon\include\errordefs.h(5) : error C2143: syntax error : missing ';' before 'enum [tag]'
next:
#ifndef EN_SMS_SRC_TAO2CPP_H_
#define EN_SMS_SRC_TAO2CPP_H_
#include "SystemMonitorMasterServiceC.h"
#include "SystemMonitorSlaveServiceC.h"
#include "CommonDefs.h"
#include "SystemMonitorServiceDataDefs.h"
namespace EN
{
namespace SMS
{
template < typename _Ty, typename _Cy>
inline
void Tao2Cpp_Enum(_Ty taoValue, _Cy &cppValue)
{
cppValue = (_Cy)taoValue;
}
error C2143: syntax error : missing '}' before 'namespace'
A lot of errors like above.
Thanks. I waste some time to make it easy to read.
You need a semi-colon in the enum declaration:
enum ENReturnCode
{
...
};