I need my program to print out the name of the computer. Is this possible through C++ at all?
Thanks in advance.
I need my program to print out the name of the computer. Is this possible through C++ at all?
Thanks in advance.
Code:#include<windows.h> char buffer[256]; DWORD len = 256; GetComputerName(buffer, &len); cout<<buffer<<endl;
Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.
Thank you VERY much. Worked perfectly.Originally Posted by jinhao
-Zack
Next time, say which OS/Compiler you're using.
It was just a lucky guess that you were using windows.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Ah. Thanks. I'll be sure to state that next time. .Originally Posted by Salem
-Zack
heihei, i am so lucky
Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.
Thanks for the previous help, guys. However, I must compile it this code on a Unix machine now. I'm using the standard Unix build, cc xxx.cpp.
How should I print out the system name using that? I assume that I should include a different header file than windows.h.
Thanks in advance.
-Zack
Hum.. I dunno .. but you could try to acess the environement variables and try to see if there's something that mathces the computer name
NOTE: this main declaration ISN'T standard, although it's provided with many compilers as extension., I think. Please correct me if wrong.Code:#include <iostream> int main(int argc, char *argv[], char *env[]){ int i; for(i=0;env[i];i++){ std::cout<<env[i]<<std::endl; } return 0; }
http://www.opengroup.org/onlinepubs/...bd/envvar.html
http://www.cplusplus.com/ref/cstdlib/getenv.html
That looks good. Although I'm not sure whether it'll be fine for Unix. I will try it once I get to the office Friday.Originally Posted by xErath
Any other ideas, guys? .
-Zack
Yeah, that doesn't seem to be working on Unix machines . Any other ideas, guys? .Originally Posted by xErath
-Zack
Code:NAME uname − get name and information about current kernel SYNOPSIS #include <sys/utsname.h> int uname(struct utsname *buf);
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I get this error - fatal error C1083: Cannot open include file: 'sys/utsname.h': No such file or directoryOriginally Posted by Salem
Error executing cl.exe.
-Zack
Oh please - you asked for a unix answer and I gave you one.
Then you turn around and try and compile it with a windows compiler!
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
It has to work on both .Originally Posted by Salem
-Zack
Tough - it won't, nor can it ever work on both.
Certainly, there's no standard way to find out.
I suppose you could find some very common library somewhere, which might happen to tell you which machine you're on...
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.