Im trying to print a string to console in c++ console application.
void Divisibility::print(int number, bool divisible) { if(divisible == true) { cout << number << " is divisible by" << divisibleBy << endl; } else { cout << divisiblyBy << endl; } }
i have the correct includes etc, this error i believe is just that i simply dont know how to print to console in c++ yet and this i guess isnt the way to do it
EDIT: sorry forgot to mention divisiblyBy is the string
using printf() If we want to do a string output in C stored in memory and we want to output it as it is, then we can use the printf() function. This function, like scanf() uses the access specifier %s to output strings. The complete syntax for this method is: printf("%s", char *s);
Running the program in normal mode, not debug mode, then all printf's are shown in the console tab. Output buffering really is the reason why outputs of printf statements are not visible in the console tab during debugging. setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0);
printf() This is mainly used in C language. It is a formatting function that prints to the standard out. It prints to the console and takes a format specifier to print.
C provides two basic ways to read and write strings. input/output functions, scanf/fscanf and printf/fprintf. Second, we can use a special set of string-only functions, get string (gets/fgets) and put string ( puts/fputs ).
yes it's possible to print a string to the console.
#include "stdafx.h" #include <string> #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { string strMytestString("hello world"); cout << strMytestString; return 0; }
stdafx.h isn't pertinent to the solution, everything else is.
All you have to do is add:
#include <string> using namespace std;
at the top. (BTW I know this was posted in 2013 but I just wanted to answer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With