How to get current working directory in cpp? [duplicate] - c++

This question already has answers here:
Is there a C++ equivalent to getcwd?
(8 answers)
Closed 2 years ago.
I'am familiar that getcwd() function is available in c to get current working directory.Is there a std function in cpp for the same?

Yes.
C++17 has std::filesystem::current_path.
On a POSIX system, you can also just keep using getcwd(). getcwd() is not actually part of C. Even it were, you could still keep using it, as the C Standard Library is available in C++; however, you've probably heard that it is preferable to use the C++ Standard Library where possible, and that's largely true.

Use current_path() method in boost::filesystem or std::filesystem::current_path() in c++17

Related

Why use stdio.h instead of iostream.h in C++ [duplicate]

This question already has answers here:
Speed and stability of libraries 'stdio' vs. 'iostream' [closed]
(4 answers)
Closed 7 years ago.
So I'm at university second semester and we are learning Data Structures. Back in first semester we used to learn C, and now we are moving on C++ (I guess due to the OOP, which allows us to implement those data structures).
But apparently we are still including C's libraries instead of C++'s. I'm aware that stdio is for C and iostream is for C++. I'm wondering why use stdio instead of iostream? is cout << bad/slow/etc?
It's because your "professor" is used to it, and is teaching obsolete/antiquated techniques.
It won't do you much good in the real world.
This is even more apparent by your use of the name "iostream.h" — this suggests you're being taught on Turbo C++ using a DOS emulator, as if it's still 1991. It's not still 1991. In real C++ it's just "iostream".
The world moved on some twenty years ago.
Well done for asking, though. So so so so so so so so many don't. :(

C++ multithreading without C++11? [duplicate]

This question already has answers here:
Is there any cross-platform threading library in C++?
(12 answers)
Closed 8 years ago.
C++11's threading library is wonderful looking. It's small, simple, standard, and portable. Unfortunately, I'm locked to Visual Studio 2010 which obviously doesn't have that available to it.
My questions are, what multi-threading libraries are available that provide a similar level of functionality, while being portable and reliable? Is it possible (physically and legally) to obtain the corresponding <thread> library to use in VS2010? Are there disadvantages to using a separate library (maybe not as actively maintained since C++11 fills that role, etc)?
First, take a look on wikipedia list of C++ multi-threading libraries. Some very well documented library can by POCO C++. However, you can also see related question Is there any cross-platform threading library in C++?.

Is the C++ standard library thread safe? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Do I need to protect read access to an STL container in a multithreading environment?
I am using the C++ standard library which comes with (Linux) GCC or (Windows) VC.
Can anyone please say clearly whether or not this library is thread safe?
"Thread safe" is not a clearly-defined boolean property of a library. Some things can be done concurrently and others cannot.
Almost certainly if you were to ask a more detailed question specifying what it is you want to do, the answer would be "no, it is not thread-safe". But only almost.
If by "thread-safe" you mean something like the difference between Vector and ArrayList in Java, then C++ standard containers are non-thread-safe.

Standard Library for C [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
C Analog To STL
Is there something like STL for C.
You can have a look at the glib, which provides lots of interesting features
well there is the C library of course :) but I do not see the use of templates for C
There's not really anything quite like the STL; but there are a lot of libraries. glib has been mentioned, but usually it's not always useable together with whatever libraries you are using for actually achieving what you want to do.

Is there any standardized and commonly-used library for C (C99 or whatever), as STL is for C++? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Container Class / Library for C
I expect I'd be forced to use vectors, lists and sets for my C program. Should I invent those entities from scratch, or there is some kind of standard library for C as STL is for C++ ?
C doesn't have templates, so it might be difficult to implement those C++ collections in a generic way. I'm not aware of any libraries that implement those features in C.
If I were faced with such a situation, my first thought would be to isolate the parts
of my program that would benefit from C++ features, write them in C++, then provide
an extern "C" interface to those modules so they could be called from the pure C
parts of the program. Is that an option for you?
You can look at APR, or GLib. Those are widely used portable C libraries with everything you need not to reinvent the wheel each time.
There is a standard c library, but it does not have any support for built-in container types such as the ones you list.