我正在尝试将网络摄像头用于Android模拟器,但无论我做什么,都会出现#include <iostream>
#include <cstring>
#include <string>
using namespace std;
class Pizza {
private:
char name[15];
int price;
char *ingredients;
int reduction;
public:
Pizza (char *name= "", int price= 0, char *ingredients= "", int reduction= 0) {
this->ingredients= new char [strlen(ingredients)+1];
strcpy(this->ingredients, ingredients);
strcpy(this->name, name);
this->price= price;
this->reduction= reduction;
}
~Pizza () {
delete [] ingredients;
}
bool areSame(Pizza p) {
for (int i = 0; i < strlen(this->ingredients) + 1; i++)
if (this->ingredients[i] != p.ingredients[i])
return true;
return false;
}
int getReduction() {
return reduction;
}
void print() {
cout << "name: " << name<< " ingredients: " << ingredients<< " Price: " << price;
}
};
class Pizzeria{
private:
char name[15];
Pizza *p;
int number_of_pizzas;
public:
Pizzeria(char *name= "") {
strcpy(this->name, name);
p = new Pizza [0];
number_of_pizzas = 1;
}
Pizzeria(const Pizzeria &x) {
this->p = new Pizza [x.number_of_pizzas-1];
for (int i = 0; i < number_of_pizzas; i++) {
this->p[i] = x.p[i];
}
this->number_of_pizzas= x.number_of_pizzas;
strcpy(this->name, x.name);
}
~Pizzeria() {
delete [] p;
}
void addPizza(Pizza P) {cout<<"fsfas";
for (int i = 0; i < number_of_pizzas; i++) {
if (!(p[i].areSame(P))) {
number_of_pizzas++;
p[number_of_pizzas] = P;
return;
}
}
}
void pizzasOnPromotion() {
for (int i = 0; i < number_of_pizzas; i++)
if (p->getReduction() > 0)
p->print();
}
void setName(char *name) {
strcpy(this->name, name);
}
char getName() {
return *name;
}
};
int main () {
int n;
char name[15];
Pizzeria p1(name);
cin >> name;
cin >> n;
int reduc;
for(int i = 0; i < n; i++){
char imp[100];
cin.get();
cin.getline(imp,100);
int price;
cin >> price;
char ingredients[100];
cin.get();
cin.getline(ingredients,100);
cin >> reduc; cout << "pls work";
Pizza p(imp,price,ingredients,reduc);
p1.addPizza(p);
}
Pizzeria p2 = p1;
cin >> name;
p2.setName(name);
char imp[100];
cin.get();
cin.getline(imp,100);
int price;
cin >> price;
char ingredients[100];
cin.get();
cin.getline(ingredients,100);
cin >> reduc;
Pizza p(imp,price,ingredients,reduc);
p2.addPizza(p);
cout<<p1.getName()<<endl;
cout<<"Pizzas on promotion:"<<endl;
p1.pizzasOnPromotion();
cout<<p2.getName()<<endl;
cout<<"Pizzas on promotion:"<<endl;
p2.pizzasOnPromotion();
return 0;
}
错误。
使用的程序:
Can't connect to the camera
Microsoft Windows 10 Pro, Version 10.0.16299 Build 16299
我尝试以管理员身份启动Android Studio 3.0.1
,但错误仍然存在。但是,当我查看使用相机的权限时,我看不到Android Studio
或Android Studio
。我该如何解决这个问题?
答案 0 :(得分:1)
我也有这个问题。我设法通过更新Android模拟器解决了这个问题。 sdk管理器中有可用的更新。 安装更新后,我的网络摄像头开始在模拟器上正常工作。
答案 1 :(得分:0)
这是因为您已将前置摄像头和后置摄像头都设置为相同的硬件设备,即webcam0。尝试改回仿真状态,它将得到修复。
答案 2 :(得分:0)
从 Webcam0>模拟
更改摄像头设置(前后)