먼저 내가 기능 "Nieuwe의 bestelling"에 가서는, 느릅 나무는 나를 벡터를 채울 수 있습니다. 그 후 나는 함수 toevoegen와 벡터를 인쇄하지만 여전히
빈이야 - 내가
감사합니다 사전에 일식 루나을 사용하고 있습니다!
코드 :
int main(void)
{
tafel tafelObj;
short choice;
cout<<(" 1. nieuwe bestelling\n 2. tafel instellingen);
cin>>choice;
switch(choice)
{
case(1): cout<<"nieuwe bestelling"<<endl;
tafelObj.nieuwebestelling();
break;
case(2): cout<<"tafel instellingen"<<endl;
tafelObj.toevoegen();
break;
}
}
주요. /* * tafel.cpp 가 *에 만든 : 2014년 7월 18일 * 저자 : 알렉스 */
#include "../tafel.h"
#include <vector>
#include <string>
#include <iostream>
tafel::tafel() {
//constr
}
void tafel::nieuwebestelling()
{
std::string besteld;
static int tafelnummer=1;
while(besteld!= "end")
{
std::cout<<"bestelling: ";
std::getline (std::cin,besteld);
bestellingen[tafelnummer].gerechten.push_back(besteld);
}
std::cout<<"---------------------------"<<std::endl;
}
void tafel::toevoegen()
{
int tafelnummer=1;
std::cout<<"----------------------------------"<<std::endl;
std::cout<<"gewijzigd"<<std::endl;
for(unsigned int i =0; i< bestellingen[tafelnummer].gerechten.size(); i++)
{
std::cout<<"i";
std::cout<< bestellingen[tafelnummer].gerechten[i]<<std::endl;
}
std::cout<<"eind"<<std::endl<<std::endl;
std::cin>>tafelnummer; //This is just here so i can clearly see, the point where everything should be printed
}
.
int main()
{
tafel t;
t.nieuwebestelling();
t.toevoegen();
return 0;
}
그러나, 당신의 코드에서 버그를 지적하기 위하여려고하고있다 :
/*
* tafel.h
*
* Created on: 18 Jul 2014
* Author: alex
*/
#ifndef TAFEL_H_
#define TAFEL_H_
#define tafels 10
#include <iostream>
#include <vector>
#include <string>
class tafel {
public:
static int i;
struct bestelling //elke tafel heeft een struct waarin alle gerechten enzo in staan. ide struct = ide tafel
{
std::vector<std::string>gerechten;
}bestellingen[tafels];
tafel();
void nieuwebestelling();
void toevoegen();
};
#endif /* TAFEL_H_ */
벡터 배열이 있습니다 ... 왜 벡터 벡터로 만들지 않습니까? 또는 적어도 배열 배열. 또는 일관된 무언가! 또한, 우리에게'main'을 주시겠습니까 – scohe001
@Josh 구조체를 사용한 이유는 이후에 구조체에 다른 정보를 추가 할 수 있기 때문입니다. 단지 벡터 그 이상일 것입니다 – ohiliouh
@Jacques 알고 있지만 코드의 모든 벡터를 사용하거나, 또는 모든 배열을 사용하십시오. 그들을 혼합하는 것은 좋은 습관이 아닙니다. 왜 sturcts의 벡터가 없어? – scohe001