FAQ Database Discussion Community
c++,cout,string-literals
In the following example: cout<<"\n"[a==N]; I have no clue about what the [] option does in cout, but it does not print a newline when the value of a is equal to N....
c++,arrays,cout
How to print array of LPCTSTR example LPCTSTR pszValueNames[] = { L"partnerID", L"partnerSubID", L"transactionID" }; for (int i = 0; i < (sizeof(pszValueNames) / sizeof(LPCWSTR)); i++) { cout << (*pszValueNames[i]) << endl; } Above give some numbers which is not real lpctstr values. When i use wchar_t* and all other...
c++,arrays,for-loop,cout
I'm writing a program that outputs the sum of user-input, space-separated integers (no more than 100). I'm supposed to read the values into an array such that the input "1 2 3" produces "6". This is what I have so far: #include <iostream> using namespace std; int main() { int...
c++,cout,cpu-registers
Specifically talking about the C++ part of the code here: [LINK] (intel x86, .cpp & .asm hybrid program.) From dealing with chars/strings' pointers in .asm I know it uses dl/dx registers for their storage-before-display (in case of 2h and 9h functions). How is it in the case when the data...
c++,printf,cout,sin
Using Devc++ for printf getting 0.00000 and for cout getting some weird output. #include<iostream> #include<cmath> #include<stdio.h> using namespace std; main() { float i,j=M_PI; i=sin(j); printf("%f \n",i); cout<<i; } ...
c++,stream,cout,flush
As far as I know streaming std::endl into std::cout will flush it. I get that that behavior makes sense for most applications. My problem is that I have some output that uses multiple std::endl's and therefore flushes the output. This is really bad for the performance of my program and...
c++,string,vector,output,cout
what is the easiest way to print out a vector of strings on the console? I got something like this map < int, vector<string>> and i want to print the values to a user-given key. typemap::iterator p1; cin >> i for (pointer = map.begin(); pointer != map.end(); ++pointer) { if...
c++,printing,cout,c++-standard-library
What's the C++ way to print or cout a C++ standard library container to the console, to view its contents? On a separate note, why doesn't the C++ library actually overload the << operator for you? Any history behind it?...
c++,templates,cout
This is my code: #include <iostream> using namespace std; template< typename T > T silnia( T w ) { cout << "not special" << endl; } template<> int silnia<int>( int x ) { cout << "special" << endl; } int main() { cout << silnia<double>(5) << endl; cout << silnia<int>(5)...
c++,escaping,cout
I have a logo that features many special characters, such as escape characters, and I want to print it to the terminal. How should I do this without the compiler throwing "unknown escape sequence" errors? Here is some example code (that features only one problematic character -- not, say, hundreds):...
c++,terminal,command-prompt,cout,clion
When I do cout << "test" in clion and then build it instead of writing it to IDE's terminal like IntelliJ, PHPStorm or any other of the Idea IDEs it opens a new command prompt window, writes it to that and them immediately closes the command prompt window so I...
c++,operator-overloading,operator-keyword,cout,ostream
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 prettiest but here's my code up to the error,...
c++,cout
What may explain why the cout is not displaying anything in this code? I know it's related to the line v[0] = 1; but I can't find out why, does someone have an explanation for it? Edit: I also know that changing v[0] = 1; for v.push_back(1); would solve the...
c++,performance,c++11,cout
I have two questions: Is two calls to std::cout less efficient than one? If yes, does the compiler (usually) optimize it and generate equal assembly for the three cases shown below? For example: std::cout << "a" << "b"; or std::cout << "ab"; or std::cout << "a"; std::cout << "b"; I...
c++,compiler-errors,g++,cout
I have data that I would like to output to files named matrix_1.txt, matrix_2.txt, etc. The following code works in visual studio: //get ready to write to file std::ofstream myfile; //define filename std::ostringstream oss; oss << "output_matrix_" << sim_index << ".txt"; myfile.std::ofstream::open (oss.str()); //write to file myfile<<"stuff\n"; //close the file...
c++,debugging,cout
I have inherited a large codebase where std::cout is very frequently used with the purpose of printing out debugging information. There is no real debug/log functionality in the code and since this will be a short lived task (bugfix) implementing debug/log functionality for now is out of the question. It...
c++,iostream,cout
I was trying to print \a but it shows nothing so I searched for this and found out it should have made a sound but it didn't either. I am using code lite on Windows 8. How to print \a? Where is that sound? This is my code: #include <iostream>...
c++,cout
I often use cout for debugging purpose in many different places in my code, and then I get frustrated and comment all of them manually. Is there a way to suppress cout output in the runtime? And more importantly, let's say I want to suppress all my cout outputs, but...
c++,string,concatenation,cout
This question already has an answer here: Why in the code “456”+1, output is “56” [duplicate] 3 answers i was learning C++ after 6-7 years of java and i have encouter a problem, in this snippet that instead of "concat" it's just remove the n character as the input...
c++,cout,flush
I am reading the following example from wikipedia. #include <iostream> int main() { std::cout << "Hello, world!\n"; return 0; } The article reads then as: This program would output "Hello, world!" followed by a newline and standard output stream buffer flush. I do not believe this is correct, since a...
c++,c++11,gcc,cout
Shall this be the example: #include <iostream> using namespace std; int main() { cout << "Hola, moondo.\n"; } It throws the error: gcc -c main.cpp gcc -o edit main.o main.o: In function `main': main.cpp:(.text+0xa): undefined reference to `std::cout' main.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char,std::char_traits<char> >& std::operator<< <std::char_traits<char>>(std::basic_ostream<char, std::char_traits<char> >&, char const*)'...
c++,cout
i'm running a C++ program that classifies data into two different categories using a threshold to distinguish between them. But It wasn't working when i cout the int that holds the data it showed this -1.#IND. Has any one ever seen that??And if they have can you tell me how...
c++,c,printf,cout
I have to rewrite a logging system in C++ as part of project requirements (everything has to be C++ instead of C now), and there are a number of ways in which we log things like mathematical data and pointer addresses. It is fairly common to see a log like:...
c++,string,cout
I am in midway of implementing fairplay algorithm, but I noticed that cout statements are not working Below is my code. Note that all required header files are included and there are no compilation errors (by far my knowledge). The program runs without errors and I get terminated command (again,...
c++,cout
I want to know actual difference between cout<<cout and cout<<&cout in c++? In my compiler cout<<cout returns 0x477864 & cout<<&cout returns 0x477860 at any time.It shows it has 1 digit of difference between them.What are the significance of these?
c++,string,hex,std,cout
I want to print out the hex value of an unsigned char array using the cout function. The most obvious approach would be something like the following. unsigned char str[] = "foo bar baz\n"; for(unsigned short int i = 0; i < sizeof(str); i++){ std::cout << std::hex << str[i] <<...
c++,formatting,cout
I am playing around with the setw and setfill functions but I'm absolutely stuck now. Here is my code: char separator = ' '; cout << "-" << setw(INET_ADDRSTRLEN*4 + INET6_ADDRSTRLEN) << setfill('-') << "\n"; cout << "| Name" << setw(INET_ADDRSTRLEN) << setfill(separator); cout << "| IPv4" << setw(INET_ADDRSTRLEN) <<...
c++,ternary-operator,cout
Can anyone explain the output of the following program: #include <iostream> using namespace std; int main() { int test = 0; cout << "First character " << '1' << endl; cout << "Second character " << (test ? 3 : '1') << endl; return 0; } Output: First character 1...
c++,newline,cout
I have a simple program to test a function I'm writing that detects if a text file for a maze is valid. The only allowed characters are '0', '1', ' ' (space) and '\n' (newline). However, when I execute the code with a sample text file, I get some strange...
c++,std,cout,stringstream
I have the following code for formatting a printout to always be 4 digits with sign included: std::stringstream pitch; pitch.precision(0); pitch.width(4); pitch.fill('0'); pitch << std::showpos << (int)(m_values["Pitch_1"]); I would also like to show the sign ("+"/"-"), but I want it to precede the fill, as follows: +002 However, the code...
c++,c,printf,cout,format-specifiers
int arrSize = 10; double* arr = new double [arrSize]; for(int i = 0; i < arrSize; i++){ arr[i] = i; } for(int i = 0; i < arrSize; i++){ printf("%d", arr[i]); //std::cout<<arr[i]; } Here printf() prints 0000000000. cout prints 0123456789. Why ?...
c++,c++11,line-breaks,cout,extraction-operator
In this answer I have the following code: #include <iostream> #include <vector> #include <string> #include <sstream> #include <iterator> #include <limits> using namespace std; struct station{ string _stationName; int _studentPass; int _adultPass; }; std::istream& operator>>(std::istream& is, station& rhs){ getline(is, rhs._stationName, ';'); is >> rhs._studentPass >> rhs._adultPass; return is; } int main(){...
c++,codeblocks,iostream,cout
#include <iostream> using namespace std; int main(int argc, char** argv) { cout << "Whatever"; return 0; } Cout does not work, nor printf, nor puts, nor anything. Also, I've checked the project properties and both the debug and release are set to "Console Application" and to "Pause in the end"....