Unusual error when compiling with iostream? - c++

So if I add iostream (VS 2010 express) I get these errors, can't find much on google, any ideas, didn't used to be like this, a I have is this...
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
When I try to build, I get the following error messages:
------ Rebuild All started: Project: test, Configuration: Debug Win32 ------
stdafx.cpp
test.cpp
c:\program files\microsoft visual studio 10.0\vc\include\utility(535): error C2039: 'get' : is not a member of 'std::tr1'
c:\program files\microsoft visual studio 10.0\vc\include\utility(535): error C2873: 'get' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 10.0\vc\include\utility(536): error C2039: 'tuple_element' : is not a member of 'std::tr1'
c:\program files\microsoft visual studio 10.0\vc\include\utility(536): error C2873: 'tuple_element' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 10.0\vc\include\utility(537): error C2039: 'tuple_size' : is not a member of 'std::tr1'
c:\program files\microsoft visual studio 10.0\vc\include\utility(537): error C2873: 'tuple_size' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 10.0\vc\include\ios(236): error C2039: 'hexfloat' : is not a member of 'std::tr1'
c:\program files\microsoft visual studio 10.0\vc\include\ios(236): error C2873: 'hexfloat' : symbol cannot be used in a using-declaration
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Related

C2039 and C2873 when including `<cctype>` from the STL

I'm trying to compile a project with msvc 2019 compilers that I know has been compiled before. In fact, I'm actually updating the build system for it. I've come across a strange problem with sources from the standard template library. Basically the project includes <cctype> which pulls in the following snippet:
_STD_BEGIN
using _CSTD isalnum;
using _CSTD isalpha;
using _CSTD iscntrl;
using _CSTD isdigit;
using _CSTD isgraph;
using _CSTD islower;
using _CSTD isprint;
using _CSTD ispunct;
using _CSTD isspace;
using _CSTD isupper;
using _CSTD isxdigit;
using _CSTD tolower;
using _CSTD toupper;
using _CSTD isblank;
_STD_END
But these declarations all error with the following when I compile my project.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(38): error C2039: 'isalnum': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(38): error C2873: 'isalnum': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(39): error C2039: 'isalpha': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(39): error C2873: 'isalpha': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(40): error C2039: 'iscntrl': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(40): error C2873: 'iscntrl': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(41): error C2039: 'isdigit': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(41): error C2873: 'isdigit': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(42): error C2039: 'isgraph': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(42): error C2873: 'isgraph': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(43): error C2039: 'islower': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(43): error C2873: 'islower': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(44): error C2039: 'isprint': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(44): error C2873: 'isprint': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(45): error C2039: 'ispunct': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(45): error C2873: 'ispunct': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(46): error C2039: 'isspace': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(46): error C2873: 'isspace': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(47): error C2039: 'isupper': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(47): error C2873: 'isupper': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(48): error C2039: 'isxdigit': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(48): error C2873: 'isxdigit': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(49): error C2039: 'tolower': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(49): error C2873: 'tolower': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(50): error C2039: 'toupper': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(50): error C2873: 'toupper': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(52): error C2039: 'isblank': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\cctype(52): error C2873: 'isblank': symbol cannot be used in a using-declaration
The result is the same with both c++11 and c++14. I attempted to make a minimal working example but could not because my toy project that includes and uses <cctype> compiles without problems. Therefore it must be a problem with my project settings somewhere.
I know this is going to be a tough one, but does anybody have any thoughts on what might be happening here?
I had the same error on the macOS platform; the solution for me was to #include <_ctype.h> - this header defines the is* functions.

Visual Studio All c++ functions are not members of global namespace

I recently installed Visual studio as I'm working to pick up c++ more. However in c++, even running something as simple as a hello world code yields me a huge number of errors such as
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(24,18): error C2039: 'fabs': is not a member of 'global namespace'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(24,22): error C3861: 'fabs': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(28,18): error C2039: 'fabsf': is not a member of 'global namespace'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(28,23): error C3861: 'fabsf': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(32,18): error C2039: 'fabsl': is not a member of 'global namespace'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\cstdlib(32,23): error C3861: 'fabsl': identifier not found
The error seems to be either an issue with my VS setup or my C++ Distribution. Is this a common issue? Has anyone else seen this before?
Here is the code
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}

ctime Error when including boost::filesystem

I am working on small project. The essential part is, that a video should be captured, saved and moved to another folder.
For the video part I am using FFmpeg this works without any problems. To safe information I am using tinyXML2. For copying and moving of the video files I like to use boost.
At the moment I am working on windows, and I am using CMake.
The problem is, that in the moment I include the "boost/filesystem" the compiler starts failing. After the use of google and analyzing the error messages I think that there is a problem with headers <ctime> or <time>. The file that is using <ctime> is xmltest that is passed by tinyxml2.
But to be honest I am very much clueless how and why this happens.
I already tried to switch the order of the includes as mentioned here.
I tried to exclude the file that uses ctime, but this is not possible.
I tried to work around the problem, so I don't have to use Boost, but this is hard due to the platform independency.
The log file:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(19): error C2039: 'clock_t': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(19): error C2873: 'clock_t': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(23): error C2039: 'asctime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(23): error C2873: 'asctime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(24): error C2039: 'clock': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(24): error C2873: 'clock': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(25): error C2039: 'ctime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(25): error C2873: 'ctime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(26): error C2039: 'difftime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(26): error C2873: 'difftime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(27): error C2039: 'gmtime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(27): error C2873: 'gmtime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(28): error C2039: 'localtime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(28): error C2873: 'localtime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(29): error C2039: 'mktime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(29): error C2873: 'mktime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(30): error C2039: 'strftime': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(30): error C2873: 'strftime': symbol cannot be used in a using-declaration
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(31): error C2039: 'time': is not a member of '`global namespace''
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\ctime(31): error C2873: 'time': symbol cannot be used in a using-declaration
The way I include Boost & tinyxml:
find_package(TinyXML2)
find_package(Boost COMPONENTS filesystem system REQUIRED)
...
add_executable(programm ${project_sources}
${project_headers}
${TINYXML_INC})
target_link_libraries(programm PUBLIC
Boost::filesystem
Boost::system
${TinyXML2_LIBRARIES})
target_include_directories(programm PRIVATE
${Boost_INCLUDE_DIRS}
${Boost_LIBRARY_DIRS}
${TinyXML2_INCLUDE_DIR})
target_link_directories(programm PUBLIC
${Boost_INCLUDE_DIRS}
${Boost_LIBRARY_DIRS}
${TinyXML2_INCLUDE_DIR})
The include of Boost in Util.h:
#include <string>
#include <boost/filesystem.hpp>
namespace util {
bool existens_file(std::string* path);
int existens_directory(std::string* path);
bool create_directory(std::string* path);
}
Part in xmltest where <ctime> is used:
#include "tinyxml2.h"
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <ctime>
...
XMLDocument* doc = new XMLDocument();
clock_t startTime = clock();
doc->LoadFile( argv[1] );
clock_t loadTime = clock();
int errorID = doc->ErrorID();
delete doc; doc = 0;
clock_t deleteTime = clock();
EDIT
After some Testing I tried to use <ctime> in diffrent files without the include of boost. In this case I also receive the same problems as mentioned above.
So I fixed the issue, in the ffmpeg-library is file that is called time.h or Time.h.
The misstake was that accidentally linked the directory that contained this file.
I don't know why but with the include of boost::filesystem this was triggered and the time-file of ffmpeg was used.
I resolved this problem, through removing the linked directory of ffmpeg.

Access global namespace from proxy header

I have a namespace called "access" in project. This is actually used in many places inside the project. Currently I am writing unit test case for this project. I my unit test, the io.h file getting included from the UT frame work. This io file contains c function called "access". So when I tried to include both the io file and one of my project file, I got the re-definition error for "access".
So I tried to use the proxy header for solving the above problem. For proxy header I included the frame work header file in a namespace to avoid re-definition error.
But that frame work file accessing some global namespaces. So I am getting more issues with that. Is there any way to solve the issue without renaming the namespace.
Here is my sample code.
#pragma once
#include "io.h"
#include <iostream>
class Class01
{
public:
Class01(void);
~Class01(void);
void function() {
std::cout<< " Write something";}
};
#pragma once
namespace access
{
class Class02
{
public:
Class02(void);
~Class02(void);
};
}
proxy header
#pragma once
namespace sample
{
#include "Class01.h"
};
#include "Class02.h"
// NamespaceRedef.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
//#include "Class02.h"
//#include "Class01.h"
#include "proxyHeader.h"
using namespace sample;
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
When I compile the code, I got the following error...
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2039: 'acosf' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2873: 'acosf' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2039: 'asinf' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2873: 'asinf' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2039: 'atanf' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2873: 'atanf' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2039: 'atan2f' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2873: 'atan2f' : symbol cannot be used in a using-declaration crosoft visual studio 10.0\vc\include\cmath(20): error C2873: 'atanf' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2039: 'atan2f' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2873: 'atan2f' : symbol cannot be used in a using-declaration

Why won't this code compile and run in Visual Studio 2010?

I am trying to get Visual Studio 2010 set up to do plain old ANSI compilation, without Microsoft extensions of any kind.
I started with an empty project template, since there doesn't seem to be a plain ANSI project template in 2010 anymore.
Then I set
Properties -> Configuration Properties -> C/C++ -> Language -> Disable Extensions = Yes (/Za)
Here is my code:
#include <iostream>
int main( int argc, const char* argv[] )
{
std::cout << "Hello World!";
return 0;
}
Here are the errors:
1>------ Build started: Project: ansi_test, Configuration: Release Win32 ------
1>Build started 4/27/2011 4:20:00 PM.
1>InitializeBuildStatus:
1> Touching "Release\ansi_test.unsuccessfulbuild".
1>ClCompile:
1> Main.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(636): error C3861: 'width': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(636): error C3861: 'width': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(639): error C3861: 'flags': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(643): error C2227: left of '->sputc' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(643): error C2780: 'void std::fill(_FwdIt,_FwdIt,const _Ty &)' : expects 3 arguments - 0 provided
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(2712) : see declaration of 'std::fill'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(643): error C3861: 'rdbuf': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(648): error C2227: left of '->sputc' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(648): error C3861: 'rdbuf': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(654): error C2227: left of '->sputc' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(654): error C2780: 'void std::fill(_FwdIt,_FwdIt,const _Ty &)' : expects 3 arguments - 0 provided
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(2712) : see declaration of 'std::fill'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(654): error C3861: 'rdbuf': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(659): error C3861: 'width': identifier not found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.63
How do I get this, the most basic of C++ code to compile cleanly?
The error disappears if you define wchar_t as native type.
If I copy your code into a file, test.cpp and then issue the command
cl /Za /EHsc test.cpp
then it compiles cleanly without any warnings or errors on my install of visual c++ express 2010. /EHsc is necessary in order to handle exceptions properly and I don't really understand why it isn't the default.
Is this different from what you are doing?