logo
down
shadow

How can I add a char to an istringstream?


How can I add a char to an istringstream?

By : Duane Smeckert
Date : November 16 2020, 04:01 AM
will help you I'm trying to add a char to an istringstream - as so: ,
I'm trying to add a char to an istringstream
code :
ostringstream output_buffer;    

while (is.get(c)) {
    output_buffer << c;
}


Share : facebook icon twitter icon
How to create C++ istringstream from a char array with null(0) characters?

How to create C++ istringstream from a char array with null(0) characters?


By : AX5
Date : March 29 2020, 07:55 AM
around this issue I have a char array which contains null characters at random locations. I tried to create an iStringStream using this array (encodedData_arr) as below, , There is nothing special about null characters in strings
code :
std::istringstream iss(std::string(data, N));
setBlob(&iss);
std::istringstream iss("haha a null: \0");
std::istrstream iss(data, N);
struct myrawr : std::streambuf {
  myrawr(char const *s, size_t n) { 
    setg(const_cast<char*>(s), 
         const_cast<char*>(s), 
         const_cast<char*>(s + n));
  }
};

struct hasb { 
  hasb(char const *s, size_t n)
   :m(s, n)
  { }
  myrawr m;
};

// using base-from-member idiom
struct myrawrs : private hasb, std::istream {
  myrawrs(char const *s, size_t n)
    :hasb(s, n), 
     std::istream(&static_cast<hasb*>(this)->m)
  { }
};
How to initialise std::istringstream from const unsigned char* without cast or copy?

How to initialise std::istringstream from const unsigned char* without cast or copy?


By : user3317007
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Your answer is still copying.
Have you considered something like this?
code :
const unsigned char *p;
size_t len;

std::istringstream str;
str.rdbuf()->pubsetbuf(
    reinterpret_cast<char*>(const_cast<unsigned char*>(p)), len);
Read lines from istringstream ,without '\r' char at the end

Read lines from istringstream ,without '\r' char at the end


By : Sarika
Date : March 29 2020, 07:55 AM
Does that help I have a following function : , You can remove the '\r' from the end using this code:
code :
if(line[line.length() - 1] == '\r') line = line.substr(0, line.length() - 1);
std::istream& univGetline(std::istream& stream, std::string& line)
{
    std::getline(stream, line);
    if(line[line.length() - 1] == '\r') line = line.substr(0, line.length() - 1);
    return stream;
}
void process (std::string str)
{
    std::istringstream istream(str);
    std::string line;
    std::string specialStr("; -------- Special --------------------");

    while (univGetline(istream,line))
    {
      if (strcmp(specialStr.c_str(), line.c_str()) != 0)
      {
          continue;
      }
      else
      {
         //special processing
      }
    }
}
Is there a way I can read two char from the istringstream?

Is there a way I can read two char from the istringstream?


By : daidailanlan
Date : March 29 2020, 07:55 AM
I wish this helpful for you
I expect the output of 78 5 + to be 83. However I am getting 13.
code :
int postFixEval(string str)
{
    istringstream in = istringstream(str);
    stack<int> postFixStack;
    skipWhiteSpace(in);

    while (in)
    {
        char ch = in.peek();
        if (isdigit(ch)) {
            int num;
            in >> num;
            postFixStack.push(num);
        }
        else {
            char op = in.get();
            if (op == '+') {
                int num1 = postFixStack.top();
                postFixStack.pop();
                int num2 = postFixStack.top();
                postFixStack.pop();
                postFixStack.push(num1 + num2);
            }
        }
    }
    return postFixStack.top();
}
How to convert istringstream object to string and char array?

How to convert istringstream object to string and char array?


By : austin
Date : March 29 2020, 07:55 AM
This might help you I have this object: , For a std::string:
ob_stream.str();
Related Posts Related Posts :
  • C++ on Vistual Studio with CMake error: manifest 'build.ninja' still dirty after 100 tries
  • Is there a way to automatically resolve an overloaded method via a template parameter?
  • Fastest way to find pair in a vector, remove it while iterating
  • error C2440: '=': cannot convert from 'const char *' to 'LPCWSTR'
  • Unable to call boost::clear_vertex while using listS for the vertex and edge lists
  • Decoding binary data from serial port
  • Pattern to Implement an OO interface to a C program written in an imperative style
  • CEPH + Librados++ is not returning consisten results
  • `LoadLibraryExW` triggers exception `0xC0000023` from `NtMapViewOfSection`
  • static_cast to a struct type to access all of its member variable
  • Forward declaration for boost::intrusive_ptr class to reduce compile time
  • How to use priority_queue with a non-static compare method of class instance?
  • Template parameters inside and outside class/struct
  • Determining prime number
  • How to resolve ambiguity between constructors taking std::string and std::vector
  • My program crashes when I try to change private values from an object
  • Unordered_map with custom class as key
  • Strict aliasing rules broken with templates and inheritance
  • C++ Derived Class Override Return Type
  • singly linked list c++ constructor, destructor and printing out
  • How to clone class with vector of unique_ptr to base class
  • error: no match for operator
  • std::vector doesnt accept my struct as template
  • selection of people's contours
  • how to fix the (Error using mexOpenCV) on matlab?
  • Is or was there a proposal for c++ to use the context for short enum values?
  • Fair assumptions about std::hash implementations
  • undefined reference to libusb using cyusb
  • Function returns null pointer instead of address
  • C++17 copy elision and object destruction
  • Input multiple strings via operator>> c++
  • Avoiding overflow boost container
  • How to Write a Lambda Wrapping a Function with Optional Return Value
  • Partial specialization with more template parameters
  • How to convert fixed size array to pointer on pointer array
  • Memory leak in const member constructor with tag dispatching
  • C++ function with a generic and optional class
  • Custom QGraphicsItem That Contains Child QGraphicsItems
  • Are There Restrictions on What can be Passed to auto Template Parameters?
  • Rotating line inside rectangle bounds
  • Why do I need dynamic memory allocation if I can just create an array?
  • How can I convert a text file into a form that MPI_Bcast can send?
  • How to get array of all `this` of an instance
  • Using pointers as parameters
  • Automatic type deduction with const_cast is not working
  • Why does std::is_rvalue_reference not do what it is advertised to do?
  • Function Template Specialization with Forward Declared Type
  • template deduction failed in vector
  • Is there a signed `sizeof` alternative in Qt
  • clarification on overloading the -> operator
  • What is __m128d?
  • QtConcurrent: why releaseThread and reserveThread cause deadlock?
  • Function receiving different value than passed
  • Can C++ close a '''fstream''' variable after '''.close()'''?
  • Is it necessary to overload operator in this specific case
  • Comparing an element of a string array with a string
  • how to dereference a pointer of a map of pointers to objects in c++
  • How recursive function control flow change for static variable?
  • SDL 2 blitting BMP File
  • Why does an extremely large value cause this code to repeat infinitely?
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org