I am trying to compile some code using version 4.0 of Visual C++ Studio.
I understand that I need to use the standard template library for this code, here is where the compiler stops with an error:
#include <fstream>
fatal error C1083: Cannot open include file: 'fstream': No such file or directory
Looking at the compiler install disk the STL files are not installed with the compiler, but I found the subdirectory where they are on the install disk. I have never used the STL and am not sure where exactly to place the files. For now I have placed them in a subdirectory of my source files and added that directory to Build->Settings->Resources->Additional Resource Include Directories. Also note there is no file named fstream or fstream.h in the STL directory.
In the read.me is this note:
(1) STL is the container, iterator, algorithm part of the C++ standard
library, it is not the complete standard library. (I/O streams, strings,
etc. are not included in this package.)
So I am a bit confused - do I need to get additional source files somewhere, or how should I proceed? Thanks for any help!
Visual C++ 4.0 is OLD!. It doesn't support STL properly. You should use at least use VC++ 6.0 (which does at least supports most of it) or better still use VC++ 2005 or 2008 express editions. Or you can use the GNU G++ compiler (through MinGW) which implements STL very nicely.
At the time VC++ 4.0 was made , C++ was not standardized (and STL is a subset of the C++ Standard Library) so it doesn't support most STL features or implements a non-standard version of them.
Related
I opened a solution file in VS CE 2019 and tried building the solution and ended up with a lot of C2039 errors saying that certain things weren't members of std namespace. Those were able to be solved by adding the proper include statements. When I opened the same solution in VS CE 2015 (specified by the README of this project) with no changes to the code, I was able to build and run the program with only warnings. I'm not sure what to search for in order find out more information about the differences between the versions that causes this.
This happens when the code relied on indirect inclusions between library header files, which are not mandated or guaranteed by the standard, and can change from version to version.
From What's new for C++ in Visual Studio 2019:
Optimized the standard library physical design to avoid compiling parts of the standard library not directly included. This change cut the build time of an empty file that includes only <vector> in half. As a consequence, you may need to add #include directives for headers that were previously indirectly included. For example, code that uses std::out_of_range may now need to add #include <stdexcept>. Code that uses a stream insertion operator may now need to add #include <ostream>.
It could be because the project relied on some standard library headers including other standard library headers, which is possible but not guaranteed.
I want to use an std::vector for an app that I'm creating with Tizen and I can't find the right library to include to make my std::vector be recognized...
I have a syntax error...
Is there an equivalent to std::vector specific to Tizen? I searched the web but I didn't find anything...
I tried #include <vector> Tizen doesn't recognize it, that's what my problem is because in "normal" C++ it works fine. Only I'm using Tizen with Tizen IDE (Eclipse plug-in) and it doesn't recognize the library so I'm wondering which library I need to include instead (I got a fatal error: file not found when I use the include I mentioned).
I can't post images so here's a transcript of the error message:
type name requires a specifier or qualifier
syntax error
expected expression"
All of which regarding this line:
std::vector<int> vect;
OK, I found my answer. It seems Tizen is using C and not C++... I didn't see it because some libraries I sometimes use when I code in C++ were included like they should. Anyway I'm just gonna have to find the C equivalent of vector now and my problem will be solved.
https://developer.tizen.org/dev-guide/2.2.0/
The Tizen C++ application supports C++ based on the Standard C++ ANSI ISO 14882 2003, which includes the Standard Template Library (STL). This helps developers migrate the pre-existing standard library based applications to the Tizen platform with minimum effort.
More specifically, Tizen supports complete set of libstdc++v3 comprising of standard C++ functions specified in the Standard C++ ANSI ISO 14882 2003 and the entire Standard Template Library (http://www.sgi.com/tech/stl/).
These methods can be used by including the relevant header file in a standard manner, for example, "#include <stdio>".
Support for standard C++ library extended to complete set of libstdc++v3 modules, namespaces and classes.
For more information, refer to this Web site.
Remarks:
The locale based feature is not supported in Tizen.
So #include <vector> should work fine.
Since you say that you can't include any C++ headers, I suspect the problem is that the compiler is compiling your code as C instead of C++. Affirm that your file has the .cpp extension, and view the file's properties in the project to confirm that the IDE is treating the file as C++. (I don't know where that setting is, I don't have Eclipse). This link says to delete your project and create a C++ project instead of a C project, then re-import your files. This link says you can set the "File Type", but also implies it doesn't quite work.
You say: I searched the web but I didn't find anything...
Google "std::vector" The first hit is
http://en.cppreference.com/w/cpp/container/vector
which says:
Defined in header <vector>
So the answer is: Learn to use Google.
I think the wrong answer was accepted...the clue is in the tags used by the OP.
The compiler used by Tizen studio determines whether a source file or header file is C or C++ based on the file extension. So if your header file is .h and you include < vector > then the compiler will complain since there is no C equivalent library for vector.
If you rename you header to .hpp, or your source to .cpp, and recompile then it will compile without error.
I have searched Google but haven't found quite a direct answer to my queries.
I have been reading C++ Primer and I'm still quite new to the language, but despite how good the book is it discusses the use of the standard library but doesn't really describe where it is or where it comes from (it hasn't yet anyway). So, where is the standard library? Where are the header files that let me access it? When I downloaded CodeBlocks, did the STL come with it? Or does it automatically come with my OS?
Somewhat related, but what exactly is MinGW that came with Cobeblocks? Here it says
MinGW is a C/C++ compiler suite which allows you to create Windows executables without dependency on such DLLs
So at the most basic level is it just a collection of "things" needed to let me make C++ programs?
Apologies for the quite basic question.
"When I downloaded CodeBlocks, did the STL come with it?"
Despite it's not called the STL, but the C++ standard library, it comes with your c++ compiler implementation (and optionally packaged with the CodeBlocks IDE).
You have to differentiate IDE and compiler toolchain. CodeBlocks (the Integrated Development Environment) can be configured to use a number of different compiler toolchains (e.g. Clang or MSVC).
"Or does it automatically come with my OS?"
No, usually not. Especially not for Windows OS
"So, where is the standard library? Where are the header files that let me access it?"
They come with the compiler toolchain you're currently using for your CodeBlocks project.
Supposed this is the MinGW GCC toolchain and it's installed in the default directory, you'll find the libraries under a directory like (that's what I have)
C:\MinGW\lib\gcc\mingw32\4.8.1
and the header files at
C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++
"So at the most basic level is it just a collection of "things" needed to let me make C++ programs?"
It's the Minimalist GNU toolchain for Windows. It usually comes along with the GCC (GNU C/C++ compiler toolchain), plus the MSYS minimalist GNU tools environment (including GNU make, shell, etc.).
When you have installed a C++ implementation you'll have something which implements everything necessary to use C++ source files and turn them into something running. How that is done exactly depends on the specific C++ implementation. Most often, there is a compiler which processes individual source file and translates them into object files which are then combined by a linker to produce an actual running program. That is by no means required and, e.g., cling directly interprets C++ code without compiling.
All this is just to clarify that there is no one way how C++ is implemented although the majority of contemporary C++ implementations follow the approach of compiler/linker and provide libraries as a collection of files with declarations and library files providing implementations of these declarations.
Where the C++ standard library is located and where its declarations are to be found entirely depends on the C++ implementations. Oddly, all C++ implementations I have encountered so far except cling do use a compiler and all these compilers support a -E option (although it is spelled /E for MSVC++) which preprocesses a C++ file. The typically quite large output shows locations of included files pointing at the location of the declarations. That is, something like this executed on a command line yields a file with the information about the locations:
compiler -E input.cpp > input.ii
How the compiler compiler is actually named entirely depends on the C++ implementation and is something like g++, clang++, etc. The file input.cpp is supposed to contain a suitable include directive for one of the standard C++ library headers, e.g.
#include <iostream>
Searching in the output input.ii should reveal the location of this header. Of course, it is possible that the declarations are made available by the compiler without actually including a file but just making declarations visible. There used to be a compiler like this (TenDRA) but I'm not aware of any contemporary compiler doing this (with modules being considered for standardization these may come back in the future, though).
Where the actual library file with the objects implementing the various declarations is located is an entirely different question and locating these tends to be a bit more involved.
The C++ implementation is probably installed somehow when installing CodeBlocks. I think it is just one package. On systems with a package management system like dpkg on some Linuxes it would be quite reasonable to just have the IDE have a dependency on the compiler (e.g., gcc for CodeBlocks) and have the compiler have a dependency on the standard C++ library (libstdc++ for gcc) and have the package management system sort out how things are installed.
There are several implementations of the C++ standard library. Some of the more popular ones are libstdc++, which comes packaged with GCC, libc++, which can be used with Clang, or Visual Studio's implementation by Microsoft. They use a licensed version of Dinkumware's implementation. MinGW contains a port of GCC. CodeBlocks, an IDE, allows you to choose a setup which comes packaged with a version of MinGW, or one without. Either way, you can still set up the IDE to use a different compiler if you choose. Part of the standard library implementation will also be header files, not just binaries, because a lot of it is template code (which can only be implemented in header files.)
I recommend you read the documentation for the respective technologies because they contain a lot of information, more than a tutorial or book would:
libstdc++ faq
MinGW faq
MSDN
As I am compiling my program I am not able to include the header files as shown by the compiler, I've changed the environment variables and configured the bcc32.cfg and Ilink32.cfg file but still It didn't helped.
which version of Borland C++ are you using?
If it is Borland C++ 5.01/5.02, then it is including the OWL headers and libraries - check if they are installed.
If, on the other hand, you are trying to use the free compiler, Borland C++ 5.5, or even C++Builder, then it does not include OWL headers and libraries. Your best bet is to head over to OWLNext (the open-source upgrade for OWL) and get a version of the library that is compatible with your compiler.
When I compile a program with #include
where can I see the contents of that file, and also since that file contains declarations, where can I see the actual code used in those functions?
Is it open to everyone or is it not available to the public?
The actual code is in the platform-specific standard libraries that come with your compiler, you can see it by looking at the standard library implementation source.
Here's the documentation (and source) for libstdc++ by GNU (it comes with gcc): http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/index.html.
Download the source from one of these mirrors: http://gcc.gnu.org/mirrors.html
Generally the #included file is readable, but the library it implements is generally not readable. The include files on a mac are in /usr/include/c++.
The library code depends on the compiler. For Gnu C++ used in linux and Mac you can definitely see the code. You might have to download it. It is available at http://gcc.gnu.org/libstdc++/
I don't think Windows C++ library code is available.
It depends on what toolchain you are using, not every vendor is making his implementation public. You can have a look at the GNU C library for starters: http://www.gnu.org/software/libc/
Dinkumware, the company behind the C++ standard template library that is used in Visual Studio for example, is offering a commercial product, thus the code is not available to everyone - it really depends on your license. Some versions of Visual Studio indeed ship with the source code of the runtime included.
As for the STL, there is also STLport, an open source STL implementation.
Your best bet will indeed be the projects that gcc/g++ depend on.
The C++ standard itself is just this: a standard. The implementation of which is done by many vendors. STLport and GNU libstdc++ are both open source and can be looked at as a whole. Visual Studio ships with Dinkumware C++ standard library. It is closed source.
Nevertheless, you can always see the source of the headers by opening the include directory of your C++ standard lib. The files are named just like you include them. Much of it is implemented in headers anyway. But are pretty much unreadable to the untrained eye.
But when it comes to using the C++ library don't depend on the exact source code of it, but rather on what the C++ standard says. Don't program to an implementation, but rather to the standard.
Run this command from your command line:
find /usr -name iostream
That will tell you the directory you want.
If you use something like Visual Studio, you can put a break point and then start line-by-line stepping through your code and it will open the included files as you go along. Quickest way into a file in my opinion. Otherwise you can find the code somewhere on your PC ... on mine its in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\ostream for example, replacing ostream with iostream, sstream, etc (note that those are file names without extensions) but also if you look at the directory you'll see a lot of .h and .c files
All system headers ship with your compiler. On Linux systems, these can normally be found under /usr/include . On other platforms, the will normally live where you installed the compiler.
Commercial libraries do not normally ship source code. On linux, these can normally be found in the source pacakges.