从其他函数C++中获取函数中的变量
Obtain variables in function from other function C++
我正试图将一个变量从一个函数传递到另一个函数。我尝试过这种方法,但对我不起作用:
int c (){
int x1,x2,y2,y1;
system("cls");
cout<<"Insert Value"<<endl
cin>>x1;
return x1;
}
int cd()
{
int a;
a=c();
cout<<"X1: "<<a;
}
感谢您的帮助。谢谢
您的代码有一些问题。
首先,在c()
函数的cout
语句后面缺少一个分号。
此外,您已经指示函数cd()
应该返回int
,但您没有返回任何内容。
最后,除非显式调用这些函数,否则这些函数将不会开始执行。
试试这个:
#include <iostream>
using namespace std;
int c (){
int x1,x2,y2,y1;
cout<<"Insert Value"<<endl;
cin>>x1;
return x1;
}
int cd(){
int a;
a=c();
cout<<"X1: "<<a;
return a;
}
int main()
{
int x=cd(); //call the function to create the side effects
return 0;
}
相关文章:
- 未使用的C++未优化的静态成员函数/变量
- 内联函数/变量的外部链接
- 同一函数中的静态函数变量初始化顺序
- 将非静态成员函数C 的使用无效,而将成员功能作为函数变量
- 如何从doxygen输出中排除类的无证件成员函数/变量
- 如何在LUA C API中分配全局LUA函数变量
- 如何将函数变量传递给C lambda函数
- 通过另一个C++函数更改函数变量
- c++11 lambda 真的支持闭包吗?函数变量中存在语义冲突
- C++:静态成员不能在声明时定义,但静态函数变量可以?
- apache-frift是否支持函数变量作为参数
- 类函数/变量在使用之前必须声明
- 函数变量去哪里
- 无法使用函数变量?错误表达式必须具有类类型
- 如何在main中使用函数变量
- 每当尝试打印函数变量时,C++ cout 错误
- 是否存在查看成员函数/变量的整洁等效项
- 访问友元类之间的函数变量
- 函数到函数变量
- 一个定义规则是否强制创建一个静态函数变量