C++ from unsigned char* to stringstream: Segmentation fault (core dumped) error

I am writing a C++ code and trying to convert an unsigned char* array into a string using a stringstream.the code snippet: unsigned char * arr; do{ fill(*arr); //if I print the array here, the print operation works fine stringstream s((const char*)arr); //I also tired other castings without success cout<<s.str()<<endl; //condition...} while(condition);The do-while because I have to repeat it. The problem is that I get a Segmentation fault (core dumped) error here: stringstream s((const char*)arr);Here is a more detail...Read more

word count - Regarding Stringstreams and clearing them

I'm trying to write a program that counts how many words are in a file. This code correctly counts the number of words, but why is it that if i remove the iss.clear(); it will only count the number of words in the first line of the file? stringstream iss;while(getline(file, line)){ iss << line; while(getline(iss,word, ' ')) { size++; } iss.clear();}...Read more