podrian decirme como insertar codigos ascii dentro de ""?
si a dentro de comillas se referie algo asi:
std::string dentro_de_comillas_1 = "\\n";
o asi:
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
es 10(decimal) entonces porque se usa \n
?
si entiendo bien esa parte se usa \n
para que puede usarlo dentro de un string por ejemplo, puede ver debajo como se comporta con \n
y con 10
en algunos casos, espero le ayude.
// 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?