Hello,
I'm trying to print characters in the console at specified coordinates. Up to now I have been using the very ugly printf("\033[%d;%dH%s\n", 2, 2, "str"); But I just had to ask whether C++ had any other way of doing this. The problem is not even that it's ugly, the problem comes up when I try to make myself a prettier function lik...
I'm writing a set of unit tests that write calculated values out to files. Each test produces a square matrix that holds anywhere from 50,000 to 500,000 doubles, and I have a total of 128 combinations of test cases.
Is there any significant overhead involved in writing cout statements and then piping that output to files, or would I be...
I want cout to output an int with leading zeros, so the value 1 would be printed as 001 and the value 25 printed as 025 .. you get the idea .. how can I do this?
Thanks.
...
Can a windows message box be display using the cout syntax?
I also need the command prompt window to be suppressed / hidden.
There are ways to call the messagebox function and display text through its usage, but the main constraint here is that cout syntax must be used.
cout << "message";
I was thinking of invoking the VB msgbox co...
When I construct a boost::options_description instance like
options.add_options()
("double_val", value(&config.my_double)->default_value(0.2), "it's a double");
and later want to have the automated output of the options that are available for my program, and put
std::cout << options << std::endl;
the default value 0.2 is shown wi...
I'm trying to get a line as input from the command line. My problem is that I'm not getting the whole line, but it's being tokenized by space.
So if I entered something such as "I like Math a lot" instead of getting
"you enterend: I like Math a lot"
I get the follwoing:
EDITING MODE: Enter a command
i like Math a lot
you entered i
...
I noticed if I print out a long string(char*) using cout it seems to print 1 character at a time to the screen in Windows 7, Vista, and Linux(using putty) using Visual C++ 2008 on Windows and G++ on Linux. Printf is so much faster I actually switched from cout to printf for most printing in a project of mine. This is confusing me because...
When you create a C++ console application under Windows you automatically get the console window created for you and std::cout outputs to the console window.
I have a GUI application for which I also want to create a console window. I can create the console window using the AllocConsole() function, but how do I redirect / attach std::c...
Hi all,
I've read a bunch of posts regarding redirecting std::cout to stringstreams, but I'm having problem reading the redirected string.
std::stringstream redirectStream;
std::cout.rdbuf( redirectStream.rdbuf() );
std::cout << "Hello1\n";
std::cout << "Hello2\n";
while(std::getline(redirectStream, str))
{
// This does not work - ...
After performing some tests I noticed that printf is much faster than cout. I know that it's implementation dependent, but on my Linux box printf is 8x faster. So my idea is to mix the two printing methods: I want to use cout for simple prints, and I plan to use printf for producing huge outputs (typically in a loop). I think it's safe t...
Right now, I have a console application I'm working on, which is supposed to display and update information to the console at a given interval. The problem I'm having is that with a carriage return, I can only update one line of text at a time. If I use a newline, the old line can no longer be updated using a carriage return.
What can I...
the following code:
myQueue.enqueue('a');
myQueue.enqueue('b');
cout << myQueue.dequeue() << myQueue.dequeue();
prints "ba" to the console
while:
myQueue.enqueue('a');
myQueue.enqueue('b');
cout << myQueue.dequeue();
cout << myQueue.dequeue();
prints "ab" why is this?
It seems as though cout is calling the outermost (closest to t...
I'm running a program and redirecting cout to an outfile, like so:
./program < infile.in > outfile.o
I want to be able to read in an option ('-h' or '--help') from the command line and output a help message to the terminal. Is there a way I can do this but still have the regular cout from the rest of the program go to the outfile?...
I have a class with a bool data member that is not initialized by the constructor. If I do
cout << x.myBoolDataMember;
where x is an object of this class in which the bool has not been initialized, I sometimes get a random number rather than 0 or 1. (I'm using gcc.) Is this behavior compliant with the Standard?
...
How do you get "absolutely positioned" columns with cout, that leftaligns text and right-aligns numbers?
#include <iostream>
#include <iomanip>
using namespace std;
struct Human {
char name[20];
char name2[20];
char name3[20];
double pts;
};
int main() {
int i;
Human myHumen[3] = {
{"Mr", "Alan", "Turin...
I want to create a logger class such that with a functionality like this:
Logger log;
log << "Error: " << value << "seen" << endl;
This should print me a custom formatted message. E.g. "12-09-2009 11:22:33 Error 5 seen"
My simple class currently looks like this:
class Logger {
private:
ostringstream oss;
public:
...
I'm trying to simply print out the values contained in an array.
I have an array of strings called 'result'. I don't know exactly how big it is because it was automatically generated.
From what I've read, you can determine the size of an array by doing this:
sizeof(result)/sizeof(result[0])
Is this correct? Because for my program, ...
cout << hex << 11 << endl;
cout << 12 << endl;
will print :
a
b
If I cout 13, it will be printed as 'c'. How do I remove the hex modifier from now on so it would just print 13?
This is probably simple but I tried looking for the answer elsewhere. Thanks.
...
Hi,
I tried the following code:
#include <iostream>
using std::cout;
using std::ostream;
class X
{
public:
friend ostream& operator<<(ostream &os, const X& obj)
{
cout << "hehe"; // comment this and infinite loop is gone
return (os << obj);
}
};
int main()
{
X x;
cout << x;
return 0;
}...
Hi
In such code, what it is called, \\n like this?
cout<<"Hello\\n \'world\'!";
What's the basic rule about such characters?
...