gpt4 book ai didi

c++ - 函数和变量 "chicken or the egg"场景

转载 作者:行者123 更新时间:2023-11-28 00:32:16 24 4
gpt4 key购买 nike

我正在制作一个在 C++ 中运行的简单程序来为我执行 ffmpeg,但我遇到了需要在“main”中定义某些变量的问题,但该函数需要在 main 之上才能准备好使用.我能做什么?

#include <iostream>
#include <cstdlib>

using namespace std;

int convert()
{
int operation;
switch(operation){
case '1':

case '2':

case '3':

case '4':
;
}
return 0;
}
int main()
{
std::string formatIn;
std::string FormatOut;
std::string confirm;
cout << "select format that file is currently in: mp3, gp3, mp4, flv" << endl;
cin >> formatIn;
cout << "original format = " << formatIn << endl;
cout << "choose your target format: mp3, gp3, mp4, flv" << endl;
cin >> FormatOut;
cout << "selected format = " << FormatOut << endl;
cout << "proceed? ";
cin >> confirm;
if(confirm == "yes"){
cout << "proceeding with operation:" << endl;
convert();
}
else{
if(confirm == "no"){
cout << "canceling,,," << endl;
}
}
}

最佳答案

给函数一个参数:

int convert(int operation)
{
switch(operation){

然后在 main 中传递一个参数:

int operation = ....
int c = convert(operation);

关于c++ - 函数和变量 "chicken or the egg"场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22443708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com