473,748 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unix, "hello world"

How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.
Jul 22 '05 #1
6 4131
Matthew wrote:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.


From the hello world page:

#include <iostream>

int main()
{
std::cout << "Hello, world!\n";
}

If you are interested in various ways of doing hello world, you might find

http://www2.latech.edu/~acm/HelloWorld.shtml

ammusing.
Best

Kai-Uwe
Jul 22 '05 #2
Matthew wrote:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.


#include <iostream>

int main()
{
std::cout << "hello world" << std::endl;
return 0;
}

- Pete
Jul 22 '05 #3
Matthew posted:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.


#include <iostream>

int main(void)
{
std::cout << "Hello World!!";
}
Jul 22 '05 #4
Matthew wrote:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.


Visual C++, AFAIK, is only capable of creating executable that run
on MS Windows. Older versions could create MS-DOS executables, and
there is a cross-compiler for Mac OS.

There is another way, though. You could use a third-party product
to run a Windows executable on Unix. I've heard of WinE and VMWare.
Both are kind of "virtual machines". They would run the executable,
but slower and with limited access to OS resources.

One thing you should know, every Unix-clone OS comes with its own
version of a C compiler (and often with a C++ compiler too). So,
in order to create a program on Unix, you don't need Visual C++.

Also, it's all irrelevant to comp.lang.c++ because it's all platform
specific. Please ask the question about creating an executable from
your code either in a newsgroup for your OS or for your compiler.

V
Jul 22 '05 #5
Matthew wrote:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.


Well, first, I'd trash VC and get a compiler that generates Unix
executables...
Jul 22 '05 #6
Matthew wrote:
How would I go about creating a simple "hello world" program that will
run in UNIX. I am using MS Visual C++.


You've got a few answers, but not really the whole picture yet.

Box, Pete and Kop showed you how to write source code that's portable to
UNIX. Just use only the ANSI interface, like what Bjarne Stroustrup
describes in The C++ Programming Language, and you'll be good.

To do much else in UNIX, you'll need to use POSIX, which is an API that
most, if not all, UNIX systems support fully, so you should check it
out. Any good book that talks about UNIX programming will cover POSIX.
Example: Advanced Programming in the UNIX Environment, by W. R. Stevens.

That's how to write code for UNIX.

The next group is talking about cross compilers. A cross compiler
compiles on one type of system (example: Win 32) to a different type of
system (example: UNIX). I can't think of any cross compilers off the
top of my head. GCC (the GNU compiler) will do it, but it's very
complicated. If someone hasn't made and maintain binaries to do what
you want, it may not be worth it to try to do this yourself. The GCC
Cross-Copmile HOWTO is stale (old, out-of-date) and might not be of much
help.

The alternative is to use a library to do your dirty work for you. Wine
was mentioned (www.winehq.org). This library emulates most (not all)
windows function calls, which allows you to run BINARY windows programs
on a UNIX system. I think it'll even run .exe files directly. Check it
out if this sounds like what you are after.

There are also libraries that allow UNIX programs to run on windows.
Cygwin (www.cygwin.com) is free and gives you an environment for running
UNIX programs. Cygwin also gives you a full UNIX development
environment, so this maybe is something you should consider seriously.
Instead of tediously switching computers to test your UNIX programs, or
using a dual-boot setup, you could just run cygwin and test and develop
there, and learn something about UNIX itself at the same time. All this
without ever having to leave windows! Plus it's free. Definitely check
this out.

Also, MinGW (www.mingw.org) is a free gcc compiler for windows. It only
gives you about 80% of the POSIX environment, but runs native UNIX
programs. It's better integrated into windows than Cygwin. And it can
even run UNIX configure scripts (with MSYS, available on the same site).
But it's not a full unix environment, just a gcc compiler for windows.
It's really designed for moving from UNIX to windows with GCC, not the
other way around. But it's still good so you might want to look at it.

Finally, the best way to go might just to get some neutral (neither
Win32 nor POSIX) library. This is the way to go if you're starting from
scratch (if you're porting a large existing code base, look into the
emulation libraries above). wxWindows (www.wxwindows.com) is a portable
GUI library that gives you much more than just POSIX (no GUI in POSIX),
and is also portable to a large number of systems, win32, UNIX and
UNIX-like. There's also SDL (www.libsdl.org) which is similar to
wxWindows but lighter weight and designed for media (games, etc.) type apps.

There you go!

Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2195
by: ME | last post by:
I am trying to find a prewritten method for converting a string like this:"Hello World" to this "Hello\sWorld". I plan to use it to build a regular expression. Specifically I am looking for a method that can convert not just space (\s) but also any character that needs to be escaped in a given string. Thanks, Matt
9
6663
by: PG | last post by:
Hi gurus, I have AIX visual age C++ compiler version 5.0.2.3. I have a simple hello world program that gives compilation errors. Any help will be appreciated. Thanks PG ***test.cpp**** #include <stdio.h>
21
4116
by: Alf P. Steinbach | last post by:
Just because there seems to be a lack of post-standard _correct_ tutorials: <url: http://home.no.net/dubjai/win32cpptut/>. Disclaimer: written this evening so perhaps there are "bugs" in the presentation -- are there? Plea: if someone takes the time to convert the word document to clean xhtml perhaps with stylish clear readable layout, then it will be an incentive for me to go on to write a next part, and a next part...
33
5577
by: ankursinha | last post by:
Hi, Is it possible to write a C program that prints "Hello World" on screen without having a single semi-colon in the entire program? The extra constraint here is that u r not allowed to use if,while,switch etc. So far,i figured this could be done by insertint the printf statement in main as shown: int main(int argc=printf("Hello world")
42
9893
by: Prashanth Badabagni | last post by:
Hi, Can any body tell me how to print "hello,world" with out using semicolon Thanks in advance .. Bye Prashanth Badabagni
8
7597
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
4
6288
by: arnuld | last post by:
i am learning C and doing the exercise 1-1 of K&R2, where K&R ask to remove some parts of programme and experiment with error, so here i go: #include <stdio.h> int main () { printf('hello world\n'); }
0
1483
by: Gerardo Herzig | last post by:
Hi all. Im having some "problems" with a small concurrent plpython function. Based on a small example about concurrent programming, there is some code which works fine under python: #! /usr/bin/python import threading, random import time def myPrint(str):
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9326
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8245
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.