-
Replied To a Post in Why use "const" here?
NathanOliver, thank you very much! In additions to an assembly view, it has ICC and several versions of the GNU and LLVM implementations. -
Replied To a Post in Why use "const" here?
> once you get into a mindset of using const keyword like that it just becomes natural no matter how non or complex the method is. Yes. Yes. In this … -
Replied To a Post in Vector of a class which contains ofstream as one of its data member
std::ofstream is not a *CopyConstructible* or *CopyAssignable* type. But it is MoveConstructible and MoveAssignable. The CopyConstructor is explicitly deleted. http://en.cppreference.com/w/cpp/io/basic_ofstream/basic_ofstream The CopyAssignment operator is implicitly deleted. http://en.cppreference.com/w/cpp/io/basic_ofstream/operator%3D The CopyAssignment operator … -
Replied To a Post in Why use "const" here?
15. Use const proactively. Summary const is your friend. Immutable values are easier to understand, track, and reason about, so prefer constants over variables wherever it is sensible and make … -
Gave Reputation to Suzie999 in Why use "const" here?
Some people use const with every variable that is not meant to change, for the simple reason that it might reduce chance of bugs is complicated code due to dev … -
Gave Reputation to Suzie999 in Why use "const" here?
Some people use const with every variable that is not meant to change, for the simple reason that it might reduce chance of bugs is complicated code due to dev … -
Replied To a Post in Top books on C++?
Trustworthy (and succinct) recommendations: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list https://isocpp.org/get-started 'What is the best book to learn C++ from?' in https://isocpp.org/wiki/faq/how-to-learn-cpp -
Replied To a Post in I need to include switch case. I dont know how to use it with string
Use an *enumeration* http://en.cppreference.com/w/cpp/language/enum Something like: #include <iostream> #include <string> enum class choice_t : std::size_t { one = 1, two = 2 /* ... */, invalid = std::size_t(-1) }; std::ostream& … -
Replied To a Post in Is this the correct way to convert from java to c++
> when i run the program , its keeps waiting The proram engenders *undefined behaviour*; C++ has nothing to say about what its observable behaviour ought to be. Using unsigned … -
Replied To a Post in Singleton class modification
Use *thread storage duration* for the singleton. http://en.cppreference.com/w/cpp/language/storage_duration struct A // per-thread singleton { static A& instance() ; private: A() { /* ... */ }; A( const A& ) = … -
Replied To a Post in Is this the correct way to convert from java to c++
This is an infinite loop: `for( int i = 0, n = 2; ; ++i ) { /* ... (no break statement) */ }` A missing condition makes the implied … -
Replied To a Post in Initializing Map with two strings
The keys in the map are const objects: `const std::string`; they can't be modified directly inside the map. Something like this, perhaps: #include <iostream> #include <map> #include <string> #include <cctype> … -
Replied To a Post in copy a file from one drive to the other
The File System TS was published a couple of days back. http://www.iso.org/iso/catalogue_detail.htm?csnumber=63483 Final Draft: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4100.pdf It is just a TS, so: 'This Technical Specification is applicable only to vendors who … -
Replied To a Post in copy a file from one drive to the other
Don't know about Turbo C++. This is standard C++; it may work in Turbo C++ too. // open the source file for input (text) std::ifstream srce_file( "G:/one/file.txt" ) ; // … -
Replied To a Post in Errcodes as string constants
`<cerrno>` defines several standard integer error codes (*integer constant expressions* with type `int`). For instance, ENOENT for 'No such file or directory' http://en.cppreference.com/w/cpp/error/errno_macros `<system_error>` gives us the *scoped enum* `std::errc` … -
Replied To a Post in Main() returns without executing any code in the block?
`ScheduleFile mySchedule();` This is the declaration of a nullary function returning a *prvalue* of type `ScheduleFile` See: https://en.wikipedia.org/wiki/Most_vexing_parse int main() { // ScheduleFile mySchedule(); // declare a function ScheduleFile mySchedule … -
Replied To a Post in Handling multiple interfaces in a single class
The canonical C++ way is to use templated callbacks in conjunction with: wrapping the call in a polymorphic call wrapper `std::function<>` and currying with `std::bind()` http://en.cppreference.com/w/cpp/utility/functional/function http://en.cppreference.com/w/cpp/utility/functional/bind Sample code: http://coliru.stacked-crooked.com/a/8d4283e68de561cf … -
Replied To a Post in Addition without arithmetic operators
#include <iostream> #include <limits> #include <stdexcept> #include <algorithm> #include <cassert> // algorithm from 'Hacker's Delight' by Henry S. Warren // http://www.amazon.com/dp/0201914654 unsigned int plus( unsigned int a, unsigned int b … -
Replied To a Post in To Display Logs of One Type Only
To search for a pattern in a string, use the C++ regular expression library. Tutorial: https://solarianprogrammer.com/2011/10/12/cpp-11-regex-tutorial/ http://www.informit.com/articles/article.aspx?p=2079020 The simplest way to run code asynchronously, and retrieve the result of the … -
Replied To a Post in compile error related with const_iterator
> compile error : no matching member function for call to 'insert' There is no error in the posted code (once the missing headers are added). Since C++11, `insert()` and … -
Replied To a Post in C++ Librairies and functions
Book: The C++ Standard Library: A Tutorial and Reference (2nd Edition) by Josuttis http://www.amazon.com/Standard-Library-Tutorial-Reference-2nd/dp/0321623215 Online reference: http://en.cppreference.com/w/ Offline archive: http://en.cppreference.com/w/File:html_book_20141118.zip -
Replied To a Post in How do you handle the slow execution speed of STL during development?
GNU specific, and worth studying merely for the elegance of the design. (Note: it violates ODR, but the implementation is allowed to provide well-defined semantics for undefined behaviour.) **<begion quote>** … -
Replied To a Post in make_shared()
> is it used to substitute constructor? Yes. An exception-safe and (usually) more efficient substitute. > This function is typically used to replace the construction `std::shared_ptr<T>(new T(args...))` of a shared … -
Replied To a Post in What's wrong with my code
> The input consists of two numbers X and Y ( - 10^12 <x, y< 10^12). Well, then the essence of this exercise is to ask the student to determine and use … -
Replied To a Post in Creating C++ Libraries?
First, make sure that you understand ODR and linkage http://en.cppreference.com/w/cpp/language/definition http://en.cppreference.com/w/cpp/language/storage_duration The build mechanism is implementation specific. A Tutorial revealed via a web search: http://www.bogotobogo.com/cplusplus/libraries.php (For the record: I do … -
Replied To a Post in What's wrong with my code
#include <iostream> int main() { int x ; std::cin >> x ; // if input fails, x would be set to zero int y = 0 ; std::cin >> y … -
Replied To a Post in Finding previously defined string in input file
The file is not huge (molecules); consider reading the entire file into a data structure in memory. Perform the look ups in memory, and if the data is modified, write … -
Replied To a Post in How do you add spaces between numbers to output in C++?
#include <iostream> #include <locale> #include <iomanip> // http://en.cppreference.com/w/cpp/locale/numpunct struct space_separated : std::numpunct<char> { // http://en.cppreference.com/w/cpp/locale/numpunct/thousands_sep virtual char do_thousands_sep() const override { return ' ' ; } // separate with spaces … -
Replied To a Post in Listing files in folder - WCHAR problem
The Microsoft implementation includes the draft TR2 filesystem library. (With other compilers, `boost::filesystem` which privides like functionality can be used.) #include <iostream> #include <string> #include <vector> #include <filesystem> namespace fs … -
Replied To a Post in how to check if there is data from a file?
> f i have like getline and if it cant get anything, the program will obviously crash/not build No. `std::getline()` first clears the string and if no characters were extracted …
The End.