• Member Avatar for vijayan121
    vijayan121

    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.
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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
  • Member Avatar for vijayan121
    vijayan121

    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& …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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& ) = …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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> …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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" ) ; // …
  • Member Avatar for vijayan121
    vijayan121

    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` …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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
  • Member Avatar for vijayan121
    vijayan121

    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>** …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    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 …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in ++++x - undefined behavior?

    > I think it must be since it all occurs between sequence points. Sequence point rules were there prior to C++11. Now, those rules have been superceded by sequenced-before rules. …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in besides ::malloc() what alternatives for Windows?

    > am trying to generate prime numbers well in excess of 1Gbyte of mem. It does not matter what knid of contortions we go thrugh to allocate memory - new, …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in Hash Map Resources

    http://oopscenities.net/2012/01/20/c11-unordered-maps/ http://www.drdobbs.com/windows/user-defined-hash-functions-for-unordere/231600210 http://en.cppreference.com/w/cpp/container/unordered_map http://www.cplusplus.com/reference/unordered_map/unordered_map/
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in How can you find out which version of GCC/GNU compiler your are using?

    #include <iostream> int main() { std::cout << "GCC version is: " << __GNUC__ // major version << '.' << __GNUC_MINOR__ // minor version << '.' << __GNUC_PATCHLEVEL__ // patch << …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in besides ::malloc() what alternatives for Windows?

    > What other alternatives for Windows in memory allocation? 1. Use smart_pointers, std::string, std::vector<> etc. instead of raw pointers. http://msdn.microsoft.com/en-in/library/hh279674.aspx Unless the program has exhorbitant memory needs, this would fix …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in help with replacing part of char array w/ new one

    #include <iostream> #include <string> #include <cstring> std::string replace( const char* str, // input string; make that const-correct, std::size_t sz_str, // length of input string std::size_t start, // start pos of …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in Adding to Vector from different Class

    Read this first: http://www.cplusplus.com/articles/Gw6AC542/ Take your time; make sure you have understood it. The structure of your code should be something like this: file **game.h** #ifndef GAME_H_INCLUDED #define GAME_H_INCLUDED #include …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in Adding to Vector from different Class

    The problem with { Game g; g.addtoHallofFame(*this); } is that `g` is a local variable at block scope (automatic storage duration); it will be destroyed when the scope is exited …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in Difference between char* and char []

    > can someone help knowing the difference between > char *st="myname"; > char st[]="myname"; `"myname"` is a narrow string literal; in C++, A narrow string literal has type “**array of …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in getline ignoring line

    C++ input streams have two different modes of input. When we use the >> operator, we are doing *formatted input*; when we don't (for instance we do a `std::getline()` or …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in Declare vector with size

    #include <vector> #include <string> #include <iostream> struct A { // see: http://www.stroustrup.com/C++11FAQ.html#uniform-init // see: http://www.stroustrup.com/C++11FAQ.html#member-init std::vector<std::string> activities {1} ; // vector with initial size 1 (contains one empty string) // …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in integer overflow in expression when simulating sizeof

    > guess the C++ compiler doesn't, though. Do you think there is any specific reason for that There is an explanation in the C Rationale http://www.lysator.liu.se/c/rat/a.html Re. portability: > Although …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in integer overflow in expression when simulating sizeof

    > Why the warning doesn't occur in C++? The IS does not require that undefined behaviour must be diagnosed. The macro `#define msizeof(type) ((char*)(&type) - (char*)(&type - 1))` engenders undefined …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in Can you help me convert this code from Java to C++?

    #include <iostream> #include <ctime> namespace bday_utils { namespace { int bday = 0; int bmonth = 0; int byear = 0; void get_dumbass_birthday() { std::cout << "What is your bday …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in C++11 Compile-time String Concatenation with constexpr

    sprout::string from the Sprout C++ Libraries may be of interest. https://github.com/bolero-MURAKAMI/Sprout #include <iostream> #include <sprout/string.hpp> int main() { constexpr auto hello = sprout::to_string( "hello" ) ; constexpr auto world = …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in "constexpr" Visual Studio 2013 update 2

    > i tried this simple function but it won't compile `constexpr int multiply( int x, int y ){ return x*y ; }` The November 2013 CTP will compile it. http://www.microsoft.com/en-us/download/details.aspx?id=41151&751be11f-ede8-5a0c-058c-2ee190a24fa6=True&fa43d42b-25b5-4a42-fe9b-1634f450f5ee=True
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in Trying to Remove Vector Element

    #include <iostream> #include <vector> #include <algorithm> #include <iterator> int main() { std::vector<int> seq { 4, 9, 2, 8, 1, 3, 0, 6, 7, 5} ; const auto begin = std::begin(seq) …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in Allow only positive integers

    > Typically <ios> will be included along with <iostream>, but it's not strictly portable to rely on that behavior. The IS specifies that the header `<iostream>` must include the header …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in Overload cout.operator<< and ofstream.operator<< 'Differently'!

    Whether the output is going to (input is coming from) a file or not is determined by the dynamic type of the streambuf object, and not by the dynamic type …
  • Member Avatar for vijayan121
    vijayan121

    Replied To a Post in Equivalent iteration of 2D and 3D array flattened as 1D array?

    This is a canonical way to flatten out arrays of more than one (runtime) dimension. (The code below is for three dimensions): #include <vector> #include <memory> template < typename T …

The End.