生活随笔
收集整理的這篇文章主要介紹了
                                
[转] c++基础
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
 
                                
                            
                            
                            文章出處:https://blog.csdn.net/cxs5534/article/details/106123124
 熱愛技術,擁抱開源!
 
 
 
language: c++
 filename: learncpp-cn.cpp
 contributors:
 - [“Steven Basart”, “http://github.com/xksteven”]
 - [“Matt Kline”, “https://github.com/mrkline”]
 translators:
 - [“Arnie97”, “https://github.com/Arnie97”]
 lang: zh-cn
 
 
C++是一種系統(tǒng)編程語言。用它的發(fā)明者,
 Bjarne Stroustrup的話來說,C++的設計目標是:
 
- 成為“更好的C語言”
- 支持數(shù)據(jù)的抽象與封裝
- 支持面向?qū)ο缶幊?/li>
- 支持泛型編程
C++提供了對硬件的緊密控制(正如C語言一樣),
 能夠編譯為機器語言,由處理器直接執(zhí)行。
 與此同時,它也提供了泛型、異常和類等高層功能。
 雖然C++的語法可能比某些出現(xiàn)較晚的語言更復雜,它仍然得到了人們的青睞——
 功能與速度的平衡使C++成為了目前應用最廣泛的系統(tǒng)編程語言之一。
 
int main(int argc
, char** argv
)
{return 0;
}
sizeof('c') == 1
sizeof('c') == sizeof(10)
void func(); 
void func(); 
int* ip 
= nullptr;
#include <cstdio>int main()
{printf("Hello, world!\n");return 0;
}
void print(char const* myString
)
{printf("String %s\n", myString
);
}void print(int myInt
)
{printf("My int is %d", myInt
);
}int main()
{print("Hello"); print(15); 
}
void doSomethingWithInts(int a 
= 1, int b 
= 4)
{
}int main()
{doSomethingWithInts();      doSomethingWithInts(20);    doSomethingWithInts(20, 5); 
}void invalidDeclaration(int a 
= 1, int b
) 
{
}
namespace First 
{namespace Nested 
{void foo(){printf("This is First::Nested::foo\n");}} 
} namespace Second 
{void foo(){printf("This is Second::foo\n")}
}void foo()
{printf("This is global foo\n");
}int main()
{using namespace Second
;foo(); First
::Nested
::foo(); ::foo(); 
}
#include <iostream> using namespace std
; int main()
{int myInt
;cout 
<< "Enter your favorite number:\n";cin 
>> myInt
;cout 
<< "Your favorite number is " << myInt 
<< "\n";cerr 
<< "Used for error messages";
}
#include <string>using namespace std
; string myString 
= "Hello";
string myOtherString 
= " World";
cout 
<< myString 
+ myOtherString
; cout 
<< myString 
+ " You"; 
myString
.append(" Dog");
cout 
<< myString
; 
using namespace std
;string foo 
= "I am foo";
string bar 
= "I am bar";string
& fooRef 
= foo
; 
fooRef 
+= ". Hi!"; 
cout 
<< fooRef
; 
fooRef 
= bar
;const string
& barRef 
= bar
; 
barRef 
+= ". Hi!";