could you tell me how to insert ascii codes in ""?
if within quotes it refers something like this:
-
std::string dentro_de_comillas_1 = "\n";
or so:
-
dentro_de_comillas += (char)test;
// Example program
#include <iostream>
#include <string>
int main()
{
int test = 10; // -> \n en ascii
std::string dentro_de_comillas = "dentro_de_comillas";
dentro_de_comillas += (char)test;
std::cout << dentro_de_comillas;
std::string name;
std::cout << "What is your name? " << (char)test;
std::cout << "Hello, " << name << "!\n";
std::string dentro_de_comillas_1 = "\n";
std::cout << dentro_de_comillas;
std::cout << "What is your name? " << (char)test;
}
stdout:
dentro_de_comillas
What is your name?
Hello, !
dentro_de_comillas
What is your name?
Test Ideone
is 10 (decimal) then why is \n
used?
If I understand well that part we use \n
so that you can use it within a string for example, you can see below how it behaves with \n
and with 10
in some cases, I hope it helps you.
// Example program
#include <iostream>
#include <string>
int main()
{
std::cout << "What is your name? \n";
std::cout << "What is your name?" << std::endl;
std::cout << "---" << std::endl;
std::cout << "What is your name? 10";
std::cout << "What is your name?" << (char)10;
std::cout << "What is your name? (char)10";
std::cout << "What is your name?";
}
stdout:
What is your name?
What is your name?
---
What is your name? 10What is your name?
What is your name? (char)10What is your name?