#include<iostream>
//#include <std_lib_facilities.h>
using namespace std;
// read first and second name:
int main()
{
cout <<"please enter your first and second names\n";
string first="first";
string second="second";
string name = first + ' ' + second; // concatenate strings
// separated by a space
cout <<"Hello, "<< name << '\n';
return 0;
}
以上代码主要注意string字符串的相加,可以采用A字符串+' '+B字符串的方式进行编译,最后得出"first second".
#include<iostream>
#include<cmath>
//#include <std_lib_facilities.h>
using namespace std;
// read first and second name:
int main()
{
cout << "please enter a floating-point number: "; // prompt for a number
double n=10; // floating-point variable
cout << "n == " << n
<< "\nn+1 == " << n+1 // '\n' means “a newline”
<< "\nthree times n == " << 3*n
<< "\ntwice n == " << n+n
<< "\nn squared == " << n*n
<< "\nhalf of n == " << n/2
<< "\nsquare root of n == " << sqrt(n) // library function
<< endl; // another name for newline
}
#include<iostream>
#include<cmath>
//#include <std_lib_facilities.h>
using namespace std;
// read first and second name:
int main()
{
int a = 20000;
char c = a;
int b = c;
cout<<a<<endl
<<b<<endl
<<c<<endl;
if (a != b) // != means “not equal”
cout << "oops!: " << a << "!=" << b << '\n';
else
cout << "Wow! We have large characters\n";
}
#include<iostream>
#include<cmath>
//#include <std_lib_facilities.h>
using namespace std;
// read first and second name:
int main()
{
int i = 0;
while (i<100) {
cout << i << '\t' << sqrt(i) << '\n';
++i ; // increment i
}
}
输出一个0-99的开根号