stringstream - How to pass custom allocator to std::basic_ostringstream in C++11?

I want to use a custom allocator to allocate memory from a freelist for std::basic_ostringstream. Here is my custom allocator which I want to use:template <class Tp> struct NAlloc { typedef Tp value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; NAlloc() = default; template <class T> NAllo...Read more

c++11 - how getline works in this code

int function1(string data){ stringstream ss(data); return function2(ss); } int function2(stringstream& ss){ string val; getline(ss,val,','); return stoi(val); }If I change function2 to int function2(stringstream ss){...}It doesn't work. I would like to know why? The compliation error isuse of deleted function 'std::basic_stringstream<_CharT, _Traits, _Alloc>::basic_stringstream(const std::basic_stringstream<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits; _A...Read more

c++11 - C++ .txt read in issues. getline reading full file

first of all, forgive my code for being ugly. The tons of ideas I've been given to try to fix this code have jumbled it up after all the potential solutions that haven't worked. Basically, I'm coding a Hearthstone rip-off that reads in two .txt files with card information and battles them to see which player wins. The issue is that when I'm trying to save the player's name (the first line in the files), it saves the whole file instead of just the first line. When I have managed to fix that, the for loop used to save the information for the card...Read more

c++11 - C++ why does getline() only work on the first instance of my function?

#include <iostream>#include <string>#include <sstream>#include <vector>#include <cstdlib>//These two functions work finestd::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) { std::stringstream ss(s); std::string item; while (std::getline(ss, item, delim)) { if(!item.empty()) elems.push_back(item); } return elems;}std::vector<std::string> split(const std::string &s, char delim) { std::vector<std::st...Read more

c++11 - Importing animation keytracks into Maya

I have a human bipedal animation file format that I would like to programmatically read into Maya using the C++ API.The animation file format is similar to that of the Open Asset Importer's per-node animation structure.For every joint, there is a series of up to 60 3D vector keys (to describe the translation of the joint) and 60 quaternion keys (to describe the rotation of the joint). Every joint is guaranteed to have the same number of keys (or no keys at all).The length (time in seconds) of the animation can be specified or changed (so that y...Read more

c++11 - Unexpected value returned by use_count() of shared_ptr while retrieving from vector

The program below is outputting unexpected use_count() value when shared pointer is printed using iterator de-reference of std::vector:#include<iostream>#include<memory>#include<vector>class A;typedef std::shared_ptr<A> sharedPtr;typedef std::vector<sharedPtr> sharedPtrVect;typedef sharedPtrVect::const_iterator vectItr;class A{ public: A(int inp): m_Val(inp) { /*std::cout << "*** A ctor called: " << m_Val << " ***" <<std::endl;*/ } ~A() { /*std::cout << "### A ...Read more

c++11 - AWS C++ SDK, SQS thows access violation

Trying to create an SQS queue with AWS C++ SDK.Aws::SDKOptions options; Aws::InitAPI(options); Aws::Client::ClientConfiguration configuration; configuration.region = Aws::Region::US_WEST_2; Aws::SQS::SQSClient sqs = new Aws::SQS::SQSClient(Aws::Auth::AWSCredentials("abc", "def"), configuration);Running on Windows, 64 bit, VC++.When I run I will get an access violation: Exception thrown at 0x000007FEE4E9C83C (aws-cpp-sdk-core.dll) in TestDB.exe: 0xC0000005: Access violation reading location 0x0000000000000000.This will happen deep in the call c...Read more

c++11 - Why is the sizeof() output over the std::vector is different than the sizeof() of std::vector if vector is inside the class?

class c1 {public:std::vector<int> vc;};int main(int argc, char** argv) {std::vector<int> v2;std::cout << "Size 1" << sizeof (v2) << '\n';v2.push_back(23);std::cout << "Size 2" << sizeof (v2) << '\n';c1 obj;std::cout<<"\n Size of class is :"<<sizeof(obj);std::cout<<"\n Size of class vector is :"<<sizeof(obj.vc);obj.vc.push_back(25);obj.vc.push_back(25);obj.vc.push_back(25);obj.vc.push_back(25);obj.vc.push_back(25);obj.vc.push_back(25);obj.vc.push_back(25);obj.vc.push_back(25...Read more

c++11 - c++ char vector, deleting words with numbers in them plus whitespace after bad word

I think I'm pretty close to solving this but I get a bus error on one of the lines. I have a program that reads from a file that takes in all the words buy separating them into characters. Some words have digits or punctuations in them and the program is suppose to go throw and delete those words plus any whitespace after the bad words. Than output the new sentence. I'm went over it a bunch of times and everything looks sound to me right now so I'm stuck. I kept counts for character(Ccount), spaces(Scount), and bad character(bcount) which a...Read more

c++11 - vector of boost::function not working with _placeholder

I need your help. I tried a lot to find a solution for the problem but failed so far.Idea:Create a vector of "command tuples" like the following:typedef boost::tuple<std::string, boost::function<void()>> command_tuple;std::vector<command_tuple> commands { boost::make_tuple("command1", boost::bind(&myclass::command1, this))};If the string "command1" is used the void command1() function is called. The ID index value is based on find_if search for the string ("command1" is ID=0) on the vector.This is working fine! boost::get...Read more

c++11 - extern template class vector<unique_ptr<...>> alternative

This started out as a question of: "Why isn't it possible to explicitly instantiate an std::vector of std::unique_ptr?" as in:template class std::vector<std::unique_ptr<int>>;although following explicit instantiations and variables are fine:template class std::vector<int>;template class std::unique_ptr<int>;int main() { std::vector<int> ints; std::vector<std::unique_ptr<int>> pointers;}But the question changed to: "What would be the alternatives?"I'll post my though walk-through to answer both, si...Read more

c++11 - Segmentation Fault 11 with Maps and vector c++

I am trying to get a frequency table from a given text. But the output is showing segmentation fault 11. I don't know why. I am a newbie. Your help with the code will be very well appreciated. You can edit my code to make me learn a better method of writing code as well. Thanks a lot. #include<iostream>#include<map>#include<string>#include<vector>void make_table(vector<pair<char, int> > &table , string path){ string text = "Hello thusnvkj.ernbuilvgqboipghq3pojavnaj.,fbvlkarebihfg094why091[3tugjvlksbdfv...Read more