小编mom*_*omo的帖子

C++ Visual Studio类错误标识符字符串未定义

我上了课.头文件是:

   #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文件中包含字符串以期解决问题,但它没有用.伙计们,我真的很想要一个解决方案.

c++

2
推荐指数
1
解决办法
2万
查看次数

C++如何扫描用户的字符串输入以获取特定的单词/单词?

#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),它将不会检测到它.它有解决方法吗?是的,我使用命名空间,因为它让我的生活更轻松.

c++

2
推荐指数
1
解决办法
1541
查看次数

C++尝试制作游戏,在while循环中返回函数值时遇到问题.希望得到帮助

#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)

c++

0
推荐指数
1
解决办法
42
查看次数

无法触发 onClick 事件来切换反应状态?

我试图调试我正在制作的项目的侧边栏。侧边栏按钮之一不会触发onClick我指定的事件。我查看了 30 分钟的代码,甚至复制了它并删除了所有不必要的元素以对其进行调试。我的结论是:

  1. 我已经拥有的按钮之一可以正常工作,而我正在尝试修复的另一个按钮即使共享完全相同的代码也无法正常工作。
  2. 为什么它会这样,我无法理解。

你能找出原因吗?

这是被诅咒的代码:

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)

javascript reactjs

0
推荐指数
1
解决办法
68
查看次数

标签 统计

c++ ×3

javascript ×1

reactjs ×1