-9
사용자의 입력을 읽는 프로그램의 함수로 작업하고 있습니다. 함수는 함수가 존재하는지 확인한 다음 실행하지만 매우 버그가 있습니다. 함수는 실행되도록 설계되어 두 번 실행됩니다.함수가 입력을 읽고 함수를 두 번 실행합니다.
#include <iostream>
#include <map>
#include <windows.h>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include "userFunctions.h"//header file for functions
using namespace std;
std::string input;
//functions with a int and a string
std::map<std::string, std::function<void(int, string)>> functionsIS = {
{ "printWordWithNumber", numberPlusWord },
};
//functions with no parameters
std::map<std::string, std::function<void()>> functionsNI = {
{ "Help", userHelp },
};
void CommandCheck(std::string command){
int paramInt;
string paramString;
for (int i = 0; i < functionsIS.size(); i = i++){
if (functionsIS[command]){
std::cout << "Accessed '" << command << "' reading requirements..." << std::endl;
std::cout << "Enter paramater one (integer) : ";
std::cin >> paramInt;
std::cout << std::endl << "Enter paramater two (string)" << std::endl;
std::cin.ignore();
std::getline(std::cin, paramString);
std::cout << "running..." << std::endl;
functionsIS[command](paramInt, paramString);
}
}
for (int i = 0; i < functionsNI.size(); i = i++){
if (functionsNI[command]){
std::cout << "Accessed '" << command << "' running..." << std::endl;
functionsNI[command]();
}
}
}
int main(){
do{
std::cout << "Waiting For Command..." << std::endl;
cin >> input;
CommandCheck(input);
} while (input != "end");
return 0;
}
는 "기능"라는 헤더 파일을 만들고이 붙여 :
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void numberPlusWord(int number, std::string word){
std::cout << word << std::endl;
std::cout << number << std::endl;
}
void userHelp(){
std::cout << "I can help!" << std::endl;
}
코드가 불완전합니다. ** 게시물 **을 수정하고 [MVCE] (http://stackoverflow.com/help/mcve)를 포함하십시오. –
**'i = i ++'**하지 마라. 그것은'i ++'이어야합니다. – 0x499602D2