cout

How do I correctly organize output into columns?

The first thing that comes to my mind is to do a bunch of \t's, but that would cause words to be misaligned if any word is longer than any other word by a few characters. For example, I would like to have something like: Name Last Name Middle initial Bob Jones M Joe ReallyLongLastName T Instead,...

Displaying text in correct column

After getting a helpful answer here, I have run into yet another problem: displaying two or more strings in the column I want it to be displayed in. For an example of the problem I have, I want this output: Come here! where? not here! but instead get Come here! where? not here! when I use the code c...

Simple Detached pthread does not cancel! (cout blocks and interleaves even if mutexed)

I have a hard problem here, which I can not solve and do not find the right answer on the net: I have created a detached thread with a clean up routing, the problem is that on my Imac and Ubuntu 9.1 (Dual Core). I am not able to correctly cancel the detached thread in the fallowing code: #include <iostream> #include <pthread.h> #inclu...

Printing with fixed spaces

I want to print two strings (say "ABC" and "DEF") with 5 space characters before "ABC" and that the second string will start 7 characters after the beginning of the first string. ...

C++ print value of a pointer

I have an array of double pointers, but every time I try do print one of the values the address gets printed. How do I print the actual value? cout << arr[i] ? cout << &arr[i] ? they both print the address Does anyone know? ...

C++ alignment when printing cout <<

Is there a way to align text when priting using cout? I'm using tabs, but when the words are too big they won't be aligned anymore Sales Report for September 15, 2010 Artist Title Price Genre Disc Sale Tax Cash Merle Blue 12.99 Country 4% 12.47 1.01 13.48 Richard Music 8.49 Classical 8% 7.81 0.66 ...

Insight into how things get printed onto the screen (cout,printf) and origin of really complex stuff that I cant seem to find on textbooks

I've always wondered this, and still haven't found the answer. Whenever we use "cout" or "printf" how exactly is that printed on the screen?. How does the text come out as it does...(probably quite a vague question here, ill work with whatever you give me.). So basically how are those functions made?..is it assembly?, if so where does th...

calling std::cout.rdbuf() produces syntax error

Maybe I missed something, but I cant figure out why Visual Studio 2008 isn't seeing the rdbuf() procedure. Here is my code: 16. #include "DebugBuffer/BufferedStringBuf.h" 17. 18. BufferedStringBuf debug_buffer(256); 19. std::cout.rdbuf(&debug_buffer); The BufferedStringBuf class is from this page: http://www.devmaster.net/forums/showt...

What can explain std::cout not to display anything ?

For whatever reason, std::cout does not display anything with my application. The description of my development environment follows. I am working on a Qt application using Qt Creator. Since Qt Creator can't be launched from my station (XP64), i am currently developping it with Visual Studio 2008 and the Qt plugin (by importing the .pro ...

Operator issues with cout

I have a simple package class which is overloaded so I can output package data simply with cout << packagename. I also have two data types, name which is a string and shipping cost with a double. protected: string name; string address; double weight; double shippingcost; ostream &operator<<( ostream &output, const Pa...

Setting precision on std::cout in entire file scope - C++ iomanip

Hi all, I'm doing some calculations, and the results are being save in a file. I have to output very precise results, near the precision of the double variable, and I'm using the iomanip setprecision(int) for that. The problem is that I have to put the setprecision everywhere in the output, like that: func1() { cout<<setprecision(12)<<...

Simple noob I/O question (C++)

Hi, sorry for the noob question, but I'm new to C++. I need to read some information, line-by-line, from a file, and perform some calculations, and output into another file. For example, we read a unique ID for each line, a name, and 2 numbers. The last 2 numbers are multiplied, and in the output file, the ID, name and product are print...

Check if ostream object is cout or ofstream, c++

Is there a way in C++ to check if an ostream object is cout or a ofstream object? Something like: ostream& output(ostream& out) { if (out == cout) return out; else { out << "something different because its not going to the console" << endl; return out; } } The reason I want to do this, is that ...

C++ why do I only get the last line?

Hi, This is the text of my program: #include <iostream> #include <string> #include <sstream> #include <fstream> using namespace std; int main(){ string line; ifstream inf("grid.txt"); while(!inf.eof()){ getline(inf, line); cout << line; } return 0; } (I'll be using sstream later) This is the cont...

C++: Getting hex unexpectedly when printing array

Hi I am declaring an array using new int *a = NULL; a = new int[10]; a[0] = 23; a[1] = 43; a[2] = 45; a[3] = 76; a[4] = 34; a[5] = 85; a[6] = 34; a[7] = 97; a[8] = 45; a[9] = 22; PrintElements(a, 10); void PrintElements(int * array, int size){ for (int i=0; i<size; i++) { cout << endl << array[i]; } } Now when I pr...

Weird Error in C++ Program: Removing Printout Breaks Program

This is a very strange problem... removing the cout in the function below causes it to stop printing the correct/expected results and printing garbage values. (i.e. it still RUNS the data it outputs, though, is wrong). Any ideas? bool extract_tension(std::vector<double> &interfacial_tension_trap, std::vector<double> &interfacial...

which is faster, and which is more flexible: printf or cout?

Possible Duplicates: printf vs cout in C++ cin or printf?? I've always wondered about printf and cout.. which one is ultimately faster, and is it the most flexible as well (ie can print a range of variables, and output can be formatted)? P.S. I know this looks similar to http://stackoverflow.com/questions/2872543/printf-vs-...

Redirecting in C++

#include <iostream> #include <fstream> using namespace std; void foo(){ streambuf *psbuf; ofstream filestr; filestr.open ("test.txt"); psbuf = filestr.rdbuf(); cout.rdbuf(psbuf); } int main () { foo(); cout << "This is written to the file"; return 0; } Does cout write to the given file? If not, is there a way t...

How to remove last character put to std::cout?

Is it possible on Windows without using WinAPI? ...

Qt c++ cout, print in console

Im using Qt4 and c++ for making some programs in computer graphics. I need to be able to print some varaibles in my console in runtime, not debugging, but cout doesnt seem to work even if I add the libraries. Is there a way to do this? can some one help me? ...