#include<iostream>
int stonetolb(int);
int main(int argc, char const *argv[])
{
using namespace std;
int stone;
cout << " Enter the weight in stone" << endl;
cin >> stone;
int pounds = stonetolb(stone);
cout << stone << " stone = ";
cout << pounds << " pounds." << endl;
return 0;
}
int stonetolb(int sts)
{
return 14 * sts;
}
D:\C++pratice\c++ Primer plus>a.exe
Enter the weight in stone
15
15 stone = 210 pounds.
D:\C++pratice\c++ Primer plus>
image.png
image.png
image.png
- 如果将 using namespace std 放在特定的函数中,则表明std空间的所有元素仅在该函数的中有效。
- 如果将using namespace std放在所有函数之前,则表明std空间的所有元素在所有函数中都有效。
- 在特定函数中使用using std::cout 表明在该函数中只能使用cout对象
-
如果没有使用编译指令using,则需要加上前缀std::
image.png
1. 函数
2. 在编译之前,iostream文件中内容会在这里。
3. 让程序可以使用std空间中的所有元素。
4. cout << "Hello,world" << endl;
5. int cheeses;
6. cheeses = 32;
7. cin >> cheeses;
8. cout << "We have " << cheeses << "varieties of cheese,";
9. 函数的返回类型 函数名 函数的参数类型
整型 froop double
空类型 rattle int
整型 prune 空类型
10. 返回值类型为void.
11
可能的原因有如下:
1.没有包含头文件iostream
2.没有使用命名空间
3 .没有指出 std::cout
方法:
1. #include<iostream>
2. using namespace std;
3. std::cout
#include<iostream>
#include<string>
using namespace std;
int main(int argc, char const *argv[])
{
string str,str1;
cout << "please enter your name :";
cin >> str;
cout << "please enter your address:";
cin >> str1;
cout << "Your name is " << str << endl;
cout << "You are from " << str1 << endl;
return 0;
}
输出结果:
D:\C++pratice\c++ Primer plus>a.exe
please enter your name :Harden henan
please enter your address:Your name is Harden
You are from henan