473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Pls Tell me How to achive this

72
Hi,

int main()
{
cout<<"World";
return 0;
}

output should be Hello World.
How to achive this. This was asked in interview. I could not answer. So please help me.

Thanks,
Manju
Mar 5 '08 #1
5 1338
Parul Bagadia
188 100+
Hi,

int main()
{
cout<<"World";
return 0;
}

output should be Hello World.
How to achive this. This was asked in interview. I could not answer. So please help me.

Thanks,
Manju
I guess either u have done a mistake in posting a code or have not read it properly;
it's written as cout<<"World"; so it's but obvious that it will show output as World!
You will just have to write;

int main()
{
cout<<"Hello World";
return 0;
}
Mar 5 '08 #2
manjuks
72
I guess either u have done a mistake in posting a code or have not read it properly;
it's written as cout<<"World"; so it's but obvious that it will show output as World!
You will just have to write;

int main()
{
cout<<"Hello World";
return 0;
}
Hi,

Thanks for your reply. What i posted is correct. In interview the interviewer asked me to do this if i know C++ better. I will put his words once again. He said there is no line after cout<<"World"; and before too. I said its not possible. He said its possible but didn't tell me the solution.

Thanks,
Manju
Mar 6 '08 #3
Parul Bagadia
188 100+
Hi,

Thanks for your reply. What i posted is correct. In interview the interviewer asked me to do this if i know C++ better. I will put his words once again. He said there is no line after cout<<"World"; and before too. I said its not possible. He said its possible but didn't tell me the solution.

Thanks,
Manju
yaeh that's right;
there is no need of having a line before cout and after cout;
cout or insertion operator, puts the value of right hand variable in left operand;
in short the code should have been

cout<<"Hello world";
Mar 6 '08 #4
JonLT
41
you properly DO need a "newline" at the end of your cout line.
It could be a "\n" or a <<endl;

The reason is the the newline flushes the stdout buffer. The text isn't printed right away, but stored in the stdout buffer, so if the program terminates before the buffer is flushed the output isn't printet
Expand|Select|Wrap|Line Numbers
  1.  cout<<"Hello World!"<<endl;
  2.  
or
Expand|Select|Wrap|Line Numbers
  1. cout<<"Hello World!\n";
  2.  
or you could flush the buffer by hand:
Expand|Select|Wrap|Line Numbers
  1. cout<<"Hello World";
  2. fflush(stdout);
  3.  
Mar 6 '08 #5
whodgson
542 512MB
The following code compiles with Dev-C++ (v 4.9.9.2) but some compilers require 'return 0;'
Everything i have read and been told says the curly braces are mandatory in main() so a line is needed above and below the cout<< statement for them. If all the '\n' `s are deleted the code still compiles and runs as required.
But
Expand|Select|Wrap|Line Numbers
  1. cout<<"World";
//will not print Hello World only World.
[code=ccp]
#include<iostream>
using namespace std;

int main()
{
cout<<"Hello World\n\n";
cout<<"\n";
system("pause");
//return 0;
} [/CODE=ccp]
Mar 7 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Peter Abel | last post by:
Hi all, I'm working under W2k with Python 2.2.2 (#37, Oct 14 2002, 17:02:34) on win32 I have a file *test_data.txt* with the following content: 0123456789 0123456789 abcdefghi...
2
by: Chris McAvoy | last post by:
Is this a bug? (file is an open text file): >>> for i in range(0,5): .... var = file.next() .... file.tell() .... 1675L 1675L 1675L 1675L
3
by: N. Volbers | last post by:
Hello everyone, I noticed that when you open a zipped tarball using 'tarfile' and if you then get the pseudo-file descriptor fd for a file via 'extractfile', then fd.tell() is broken in the...
33
by: Philip Herlihy | last post by:
I'm creating a common navigation bar of text "buttons" using CSS. On each page, I want the corresponding button to be "inert" (no hover, etc) as a visual clue to where you are. I thought I'd...
1
by: Ritesh Jain via DotNetMonster.com | last post by:
Hi, How can i achive this............... There is a button on form1. On button clicking need to show form2 and close the form1(not to hide the form1) Regards, Ritesh -- Message posted via...
2
by: UJ | last post by:
I am writing an automatic download process that will update software on a computer. We've got services that run all of the time and a couple of programs that run all of the time. How can I tell if...
3
by: sara | last post by:
Hi - I have a button that runs 2 reports. If there is no data on the report, I use the No Data event, and tell the user, and Cancel the execution of that report. However, if the first report...
3
by: Magdoll | last post by:
I was trying to map various locations in a file to a dictionary. At first I read through the file using a for-loop, but tell() gave back weird results, so I switched to while, then it worked. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.