Apologies if I'm asking a silly newbie question. I'm new to C++ (familiar with C and objective C) and wanted to use the rope from the standard template library. Is this included with the libraries that Xcode uses? I have tried #include <vector> and the same for map successfully and also ext/hash_map. However rope does not seem to be available. Do I just have to download the source and include it in my project?
Unfortunately "Rope" is not part of the C++ standard!
C++ Overview: http://www.cplusplus.com/reference/
From the link you posted:
This distribution of the STL consists entirely of header files: there is no need to link to any library files.
This means the steps to use it are:
download the source code for SGI's STL implementation
add them to your include path
include files as necessary in your code
compile
That said, the link you posted is not the C++ standard library. It is an implementation of STL, (the precursor to the C++ standard library) with a few (non-standard) additions. In particular, the rope implementation you found is a non-standard adition.
Related
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 want to know, or get a clue how to search through a directory in C++ with its own standard libraries or to see if it is possible at all.
Currently I have found several solution to searching directory, but they all use some external libraries such as this SO question:
recursive folder scanning in c++
How should we approach this?
There is no filesystem facilities in the C++ standard. There is a technical specification for it which may be included in a future version of C++.
Until then, you will have to use platform specific functions or a library that wraps them. Apparently the new proposal is almost the same as boost's API, so I recommend using boost even if it's ubiquitousness wasn't good enough reason already.
When I install an IDE like VB for example, it has C++ libraries.
The question is, how to know the contents of a library (methods or manipulators) the way I am intended to do.
Where should a beginner find the contents formally? I found them in Wikipedia, but I want to know the original source (if we suppose that no internet connection is available).
MSDN would be a good source. And C++ Reference too.
You can donwload the current image of cppreference.com wiki at this address. It is updated daily.
Simple question here, when i install an IDE like vb for example, it has c++ libraries.
What libraries are you referring to?
where should a beginner find the contents formally?
Libraries that are meant for public consumption are described in their respective documentation. Where that documentation is found differs greatly. Most documentations for big public libraries are found online, on the official websites of these libraries, though.
Since the question explicitly mentioned C++, the C++ standard libraries are described at cplusplus.com. There is another large collection of C++ libraries, called Boost which is described on their homepage.
The libraries that ship with VB (which VB, though? VB.NET or VB6?) are Microsoft’s, and are therefore described on their developer network homepage, msdn.microsoft.com. An offline copy of this documentation is installed with Visual Studio; however, the software used to navigate it is barely usable (especially when accessed via Visual Studio).
The original source are the header files (.h files). In these files you will find the functions declarations and class definitions. In some cases, like template code, you will also see the implementationl. In others, the implementation will be precompiled into a .dll or .lib file and you can't see it. But all available things are in the header file. To use its contents you must #include the header file and link against the implementation. For standard library, the linking is done for you by the IDE
Everything that comes with Visual Studio and its subset installations is documented on MSDN. Do you have more specific questions re the C++ libraries? Do you need info on Win32, C runtime (CRT), C++ standard library?
Every lib usually has a coupled header (.h) file that describes the signatures of methods and types available with that library. The library is linked (or dynamically loaded and linked) with the executable while the header is used during compilation to the purpose of static checking the source.
You should just look for an include folder and check its contents.
The contents of a library is contained in the headers which ship with your IDE.
The .h files contain just the function declarations. The source containing the definitions is already compiled, so when you include a header, the linker looks for the function definitions in the libraries that you have linked. Most of the libraries are open source, some of them are just specifications that anyone can implement for example OpenGL, and the standard library is a specification, too. The same goes for the C++ language. Then programmers use the specifications to write implementations (GCC, VC++).
Here you can download the source code of STL C++ https://www.sgi.com/tech/stl/download.html
similar to iostream.h ,conio.h , ...
The standard library is generally all templates. You can just open up the desired header and see how it's implemented†. Note it's not <iostream.h>, it's <iostream>; the C++ standard library does not have .h extensions. C libraries like <string.h> can be included as <cstring> (though that generally just includes string.h)
That said, the run-time library (stuff like the C library, not-template-stuff) is compiled. You can search around your compiler install directory to find the source-code to the run-time library.
Why? If just to look, there you go. But it's a terrible way to try to learn, as the code may have non-standard extensions specific to the compiler, and most implementations are just generally ugly to read.
If you have a specific question about the inner-workings of a function, feel free to start a new question and ask how it works.
† I should mention that you may, on the off chance, have a compiler that supports export. This would mean it's entirely possible they have templated code also compiled; this is highly unlikely though. Just should be mentioned for completeness.
From a comment you added, it looks like you're looking for the source to the implementations of functions that aren't templates (or aren't in the header file for whatever reason). The more traditional runtime library support is typically separately compiled and in a library file that gets linked in to your program.
The majority of compilers provide the source code for the library (though it's not guaranteed to be available), but the source files might be installed anywhere on your system.
For the Microsoft compilers I have installed, I can find the source for the runtime in a directory under the Visual Studio installed location named something like:
vc\crt\src // VS2008
vc7\crt\src // VS2003
vc98\crt\src // VC6
If you're using some other compiler, poke around the installation directory (and make sure that you had asked that runtime sources to be installed when you installed your compiler tools).
As mentioned, it is implementation specific but there is an easy way to view contents of header files.
Compile your code with just preprocessing enabled for gcc and g++ it is -E option.
This replaces the contents of header files by their actual content and you can see them.
On linux, you can find some of them in /usr/include
These files merely contain declarations and macro definitions.The actual implementation source files can be obtained from the library provider e.g the source code of standard C++ Library(libstdc++) is obtainable here.
According to the C++ language specification, implementors do not have to put standard headers into physical files. Implementors are allowed to have the headers hard coded in the translator's executable.
Thus, you may not be able to view the contents of standard header files.
I can't seem to find the _findfirst / findfirst, _findnext / findnext API on gcc for Linux, and would actually rather use the Standard Template Library (STL) for that if it is included there.
Does anyone know what API there is available for listing files in a directory under Linux for C++ (gcc)?
It's not a C++-style API, but the API you aren't finding (the Linux/Unix correspondent of DOS/Windows-style findfirst/findnext) is opendir/readdir/closedir.
The main advantage of using opendir/readdir/closedir is that you do not need any extra library (it's part of the C library, which you are already using). In fact, the Boost filesystem library uses opendir/readdir/closedir to get the list of files in a directory.
References:
http://www.opengroup.org/onlinepubs/009695399/functions/opendir.html
http://www.opengroup.org/onlinepubs/009695399/functions/readdir.html
http://www.opengroup.org/onlinepubs/009695399/functions/closedir.html
Check out the Boost.Filesystem library.
In particular, the basic_directory_iterator.
The STL does not, yet, have functions for listing files in a directory. But it does have functions for opening files you are already aware of.
Aside from Boost.Filesystem, there is also STLSoft
Since C++17 the standard library contains std::filesystem which has its source in Boost.Filesystem. Nowadays std::filesystem::directory_iterator is the obvious choice since it is platform-independent, offers better abstraction than _findfirst/findnext/opendir/readdir/closedir and doesn't introduce any dependencies. If you can't use a C++17-compliant compiler use Boost for now and switch over later.