helloWorld.
从Hello,world! 开始吧。
| C++ | Golang |
1 #include <iostream> 2 3 int main() 4 { 5 std::cout << "Hello,world!" << std::endl; 6 return 0; 7 }
|
1 package main 2 3 import ( 4 "fmt" 5 ) 6 7 func main() { 8 fmt.Println("Hello,world!") 9 }
|
|
双冒号前面的 "std" 是标准函数库所在的namespace名字, 可以先使用using语句,这样使用标准函数库的任何对象可省掉该前缀。
1 #include <iostream> 2 3 using namespace std; 4 5 int main() 6 { 7 cout << "Hello,world!" << endl; 8 return 0; 9 }
|
import "fmt" 中的"fmt"是package fmt所在的目录名称。 不过,目录名通常和包名一致。 在import时加上点号,在使用时可以省掉package前缀。 1 package main 2 3 import ( 4 . "fmt" 5 ) 6 7 func main() { 8 Println("Hello,world!") 9 }
|

浙公网安备 33010602011771号