Questions tagged [ostream]

In C++ std::ostream is the base class for output streams.

765 questions
-3
votes
2 answers

C++ Segmentation fault after catching exception and calling cout

In my program, I get segmentation fault when calling cout << ( ball(1,0,0) ).getName(); For testing purposes when i call ( ball(1,0,0) ).getName(); I get an exception as expected and program doesn't crash. What might be wrong here? I tried…
shellnut
  • 25
  • 4
-3
votes
1 answer

overloading cout ostream operator in C++

I have a question about printing template class in c++ programing. Using Point2D class, I want to print out the template class mylist as auto x:mylist, but I keep failing. Is there any way to solve this problem without touching any classes and using…
Jaiho
  • 1
  • 1
-3
votes
1 answer

Printing a list of integers as comma separated list of numbers with max 10 per line

I have a list of numbers. I would like to print them as comma separated list of numbers, at most 10 numbers per line. The following program snippet puts in the comma separated list of numbers, without using explicit for loop to iterate the vector of…
Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
-3
votes
1 answer

Why C++ compiler doesn't provide overloaded inserter & extractor functions for class?

Consider following program. #include using std::ostream; using std::cout; using std::istream; using std::cin; class three_d { int i,j,k; public: three_d(int a,int b,int c) : i(a),j(b),k(c) { } //friend…
Destructor
  • 14,123
  • 11
  • 61
  • 126
-3
votes
2 answers

How to convert a vector to string in C++

Suppose I have a vector and I want to convert it into string, what should I do? What I got from searching on the internet is std::ostringstream oss; if (!vec.empty()) { // Convert all but the last element to avoid a trailing "," …
ronilp
  • 455
  • 2
  • 9
  • 25
-3
votes
2 answers

C++ Last Number is only 2bytes instead of 4 when writing integer to fstream

I try to write 32bit integers to file using an ostream. I'm using the << operator: ostream file; map histogram; //… file << reinterpret_cast(&histogram[i]); It works well except for the last number (in my case…
kanedo
  • 75
  • 6
-3
votes
1 answer

Trying to pass ostream to function and cout the resulting ostream

The requirement is to create an stream, pass it to second function for modification, (it has to be passed in this way since the output need to access private data members of a separate class). and then output the modified stream. It compiles as is…
teneyck
  • 1
  • 1
-3
votes
1 answer

error: identifier "ostream" is not defined

Firstly, I have looked all over for solutions and I can't seem to fix it. When trying to compile source code I get the following error. g++ -c -I/home/jcallahan/ACM/include/FANSI -I/home/jcallahan/ACM/FourtyTwo/Base…
jgCallahan
  • 33
  • 1
  • 4
-3
votes
2 answers

Why this snippet is giving me compilation error

#include using namespace std; int main() { ostream os=cout; os<<"ABC"; } This is giving me compilation error.
Nitin
  • 1
-3
votes
2 answers

Overloaded << Operator Printing Address

To the down-voters: I understand that this was a poorly constructed question. If you'll scroll down to the answers, you'll see that I discovered the source of the problem. While the question itself might not be helpful, I hope the answer will help…
Peter
  • 4,021
  • 5
  • 37
  • 58
-4
votes
1 answer

cannot print using ostream but can by using cout?

Let this be the example code: object o1(//parameters); object o2(//parameters); object o3(//parameters); object *v[3]; using std::cout; //video output ofstream of; //save on file //let's suppose v[0]=&o1; v[1]=&o2; v[2]=&o3; for (int…
-4
votes
2 answers

How the point manipulator function is working?

#include using namespace std; ostream& point(ostream& s) //Point a manipulator func { s << "-->"; return s; } int main() { cout << point << 10; return…
Udesh
  • 11
  • 4
-4
votes
1 answer

Program not writing to file like I thought it would

I thought I had this completely worked out, but it isn't actually writing anything to the file. It is opening the employeesOut.txt file but not writing anything. Any guesses? I'm getting the error Here is the input file as…
MatthewTingle
  • 355
  • 2
  • 3
  • 12
-5
votes
2 answers

Why doesn`t operator<< work successfully?

While compiling the below code, I am getting an error: Expression.h class Expression{ ... protected: std::ostream Os; }; Expression.c Expression::Expression() : Os(std::cout) { ... } Expression::Expression(std::ofstream &os) :…
-5
votes
1 answer

Error C2679: binary '<<' : no operator found (vector iterators used)

The full error message reads: Error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::_Vector_iterator< std ::_Vector_val < std::_ Simple _ types < projects > > >' (or there is no acceptable conversion) Not the…
1 2 3
50
51