How to output Polish characters in C++ console application? [duplicate] - c++

This question already has answers here:
How I can print the wchar_t values to console?
(8 answers)
Closed 9 years ago.
I've try this simple code to output polish characters using 'std::wstring' class. The class is constructed succesfully from wchar_t array but I don't know how to output it to the screen. That line "cout << X << endl ;" doesn't compile. Is it possible to output polish characters in console application written in native C++ ?. If so then how to work around this ?. Below is a simple code I did try to compile:
#include <iostream>
#include <conio.h>
#include <string>
int main(void)
{
using namespace std ;
const wchar_t data[] = {'ą', 'ę', 'ć'} ;
wstring X(data) ;
cout << X << endl ;
getch() ;
return 0 ;
}

Use std::wcout instead of cout
After using wcout you should no longer use cout in your program. The first time you cout or wcout it sets the orientation of stdout for the duration of your program.

Related

Why is there a % after a number is printed on terminal in C++? [duplicate]

This question already has answers here:
Getting a weird percent sign in printf output in terminal with C
(3 answers)
Closed last month.
I am writing code and its output is a little different from the regular ones.
#include <iostream>
using namespace std;
int main()
{
int x;
cin >> x;
cout << "Value of x: " << x;
return 0;
}
I expected only a integer but i got an output like this:Output of the above code
I would say that's you shell's prompt. You didn't print a new-line character ('\n').

Can't display characters [duplicate]

This question already has answers here:
Preventing console window from closing on Visual Studio C/C++ Console application
(24 answers)
Closed 5 years ago.
I have a piece of code that should output some text, but when I run it an empty window pops up. I want to create characters on a window. Can someone tell me why this doesn't happen?
Here is the code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
char str[] = "Hello C++";
cout << "Value of str is : " << str << endl;
return 0;
}
Thanks
Your code is fine -- but the window will automatically close when the code finishes its execution.
Consider adding a cin at the end of your code to prevent the window from closing.
int t;
cin >> t;

How to ask for input after text to show the next line in C++? [duplicate]

This question already has answers here:
Wait until user presses enter in C++?
(3 answers)
Closed 7 years ago.
I am a total newbie to C++ and I need to have 3 line of text and after every line I have to ask the user to press enter to continue. How can I do it?
Here is the code that I have so far:
#include <iostream>
using namespace std;
int main()
{
std::cout << "Es esmu dators.";
std::cout << "Es zinu C++.";
std::cout << "C++ ir programmesanas valoda";
}
You can use getchar() after each line. To use getchar() you must include cstdio.
Example code:
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
std::cout << "Es esmu dators.\n";
getchar();
std::cout << "Es zinu C++.\n";
getchar();
std::cout << "C++ ir programmesanas valoda\n";
}
From this answer:
Several ways to do so, here are some possible one-line approaches:
Use getch() (need #include ).
Use getchar() (expected for Enter, need #include ).
Use cin.get() (expected for Enter, need #include ).
Use system("pause") (need #include ).
PS: This method will also print Press any key to continue . . . on the screen. (seems perfect choice for you :))
You should also perform a quick search on the site to see if your question has been asked before, going forward.

C++ can you make a code that executes user input as a command? [duplicate]

This question already has answers here:
execute C++ from String variable
(6 answers)
Closed 7 years ago.
Hi I have been trying to make a program that will ask for the users input and whatever the user types it will execute it as a command. Sort of like CMD
#include <iostream>
#include <string>
using namespace std;
string A;
int main(){
for (int i = 0; i > -1; ++i){
cout << "Command: ";
cin >> A;
// Here Would Be The Code
cout << "Command Executed!";
}
}
Here is what i imagine a possible output (if it worked)
Command: cout << "Test";
Test
Command Executed!
You can use the system function.
http://www.cplusplus.com/reference/cstdlib/system/
system("command")

How to print characters with spaces as a string in C++ [duplicate]

This question already has answers here:
std::cin input with spaces?
(8 answers)
Closed 8 years ago.
The code is not giving desired output
when I type in a string example "Ben Parker", the output is "Goodmorning, Ben" and not the entire name("Ben Parker") what seems to be the problem?
#include <iostream>
#include <stdlib.h>
#include <cstring>
int main() {
char your_name[20];
std::cout << "Enter your name: ";
std::cin >> your_name;
std::cout << "Goodmorning, ";
std::cout.write (your_name, strlen(your_name)) << std::endl;
return 0;
}
SOLUTION
This was a very old question when I just began programming.
The entire character array can be read and printed with a for loop, or better a string type variable can be used, since it is C++.
using string your_name; seems to fix the problem, which can be then printed with a simple std::cout << your_name << endl;
You probably put a space in between "Ben" and "Parker" in input. This would cause the cin logic to believe it had an answer after seeing the space following "Ben". You will probably want to read an entire line at a time to get past that problem. See this page for an example.