我上了课.头文件是:
#pragma once
#include <string>
class Player
{
public:
Player();
private:
};
Run Code Online (Sandbox Code Playgroud)
和cpp文件是:
#include "Player.h"
#include <iostream>
Player::Player()
{
}
Run Code Online (Sandbox Code Playgroud)
当我在头文件中定义一个字符串并在头文件中向Player函数添加一个参数时,一切正常
#pragma once
#include <string>
class Player
{
public:
Player(string name);
private:
string _name;
};
Run Code Online (Sandbox Code Playgroud)
但是当我在cpp文件中向Player函数添加相同的参数时
#include "Player.h"
#include <iostream>
Player::Player(string name)
{
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:标识符"字符串"未定义,我在头文件中也得到相同的错误,所以它也会产生影响.我尝试在cpp文件中包含字符串以期解决问题,但它没有用.伙计们,我真的很想要一个解决方案.
#include <regex>
#include <string>
#include <iostream>
int main()
{
using namespace std;
string sentence;
cin >> sentence;
string word = "banana";
regex r("\\b" + word + "\\b");
smatch s;
if (regex_search(sentence, s, r)) {
cout << "success" << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到了部分工作.我输入一个包含单词banana的句子,这就是问题所在.如果我在我的句子中输入banana作为第一个单词,它将检测到它(例如:香蕉等),但如果它不是第一个单词(例如:etc banana),它将不会检测到它.它有解决方法吗?是的,我使用命名空间,因为它让我的生活更轻松.
#include <iostream>
#include <ctime>
#include <random>
using namespace std;
int playerhealth = 100;
int enemyhealth = 100;
default_random_engine random(time(NULL));
uniform_real_distribution<float> chance(0.0, 1.0);
float hit = chance(random);
int playerturn() {
if (hit > 0.5) {
enemyhealth -= 10;
return enemyhealth;
}
}
int enemyturn() {
if (hit > 0.5) {
playerhealth -= 10;
return playerhealth;
}
}
int main() {
cout << "simulating combat" << endl;
while ((enemyhealth > 0) && (playerhealth > 0)) {
playerturn();
cout << " enemy" << …Run Code Online (Sandbox Code Playgroud) 我试图调试我正在制作的项目的侧边栏。侧边栏按钮之一不会触发onClick我指定的事件。我查看了 30 分钟的代码,甚至复制了它并删除了所有不必要的元素以对其进行调试。我的结论是:
你能找出原因吗?
这是被诅咒的代码:
import React from "react";
class SidebarTest extends React.Component {
constructor() {
super();
this.state = {
isDropdownActiveFlowers: false
};
}
displayDropdownFlowers = () => {
this.setState({
isDropdownActiveFlowers: !this.state.isDropdownActiveFlowers
});
console.log(this.state.isDropdownActiveFlowers);
};
render() {
return (
<div className="sidenav">
<h1 className="Sidebar-Name">Flooo</h1>
<button onClick={this.displayDropdownFlowers}>works</button>
<button onClick={this.displayDropdownFlowers}>works</button>
<button onClick={this.displayDropdownFlowers}>works</button>
<button onclick={this.displayDropdownFlowers}>doesnt work</button>
<button onclick={this.displayDropdownFlowers}>doesnt work</button>
</div>
);
}
}
export default SidebarTest;
Run Code Online (Sandbox Code Playgroud)