Question:
how to display \n in c++ output?
Nadia
2012-09-29 05:34:29 UTC
my doctor give us home work to display \n in c++ output,,,correct this program for me
#include
{
cout<<"welcome to c++!"<<"\n";
}

i have to give her the answer 2morow :/

is it right??
Five answers:
Wertle Woo
2012-09-29 05:40:53 UTC
1. You're using a deprecated header. Take the '.h' out of iostream.

2. Where is the entry point for your program? I hope you're not actually missing main...

3. If you want to display \n, don't think of it as displaying \n, but as display a \ and an n. To display a \, you simply need \\, and to display an n, you just need n. The \ is used in escape sequences. In order to display it, it itself needs an escape sequence, which is why you need two of them.



If you actually did forget to write your main function, here's something extra to consider: You're a female. Software development is a male-dominated field because most women can't perform math or logic. In all my time in school, not one of the females who attempted my degree got past the introductory programming courses. I know every woman today likes to feel empowered and think she's exceptional, but swallow that pride and take this logic aptitude test:

http://www.kent.ac.uk/careers/tests/computer-test.htm

If you don't score well, then maybe it's time to re-evaluate your decision to attempt programming.
anonymous
2012-09-29 05:57:13 UTC
\ is called an escape character it means "the next character is NOT part of the string but is a special character) so \n adds the new line char (char 10 in ascii)



But what happens if you need to actually have "\" in your output? Well they thought of that the first \ triggers the escape and the second \ is treated as a normal \



It also works with quotes (") You cant normally put a " in a string because that closes the string! But using \" allows you to do so.



count << "welcome to \"c++"\" " << "\n"



Displays the c++ in quotes!
?
2016-12-26 13:25:41 UTC
Use a 2d array relatively of four seperate arrays const int studentScores = 5; const int studentNames = 4;//i think of you ought to use this a lower back. relatively of: int scoresS0[studentScores]; int scoresS1[studentScores]; int scoresS2[studentScores]; int scoresS3[studentScores]; use this: int rankings [ studentNames ] [studentScores]; use a for loop to get entry to all your data relatively of repeating the comparable code. for( int index_name = 0; index_name < studentNames; index_name++) { //get call and rankings GetStudentInfo(call[index_name], rankings[index_name]); .... ..... }
Abhay
2012-09-29 05:36:44 UTC
include

{

cout<<"welcome to c++!"<<"\\n";

}
kinn-j
2012-09-29 06:51:32 UTC
u should use



cout << "welcome ...."<< endl;



its "endl " without quotes..



ok



it was dat easy





http://wecodify.blogspot.in/p/android-tutorial.html


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...