小编Tyr*_*tar的帖子

执行字符串赋值时C++程序崩溃

我有一个奇怪的问题,这是我的代码:

test.h

#ifndef _test_
#define _test_
#include <iostream>
#include <string>
class Test {
public:
    Test();
    ~Test();
    void addName(std::string _Name);
private:
    std::string Name;
};
#endif // _test_ 
Run Code Online (Sandbox Code Playgroud)

TEST.CPP

#include "test.h"
Test::Test() {}
Test::~Test() {}
void Test::addName(std::string _Name) {
    std::cout << _Name << std::endl;
    Name = _Name;
    std::cout << _Name << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

main.cpp中

#include "test.h"
int main(int argc, char* argv[]) {
    Test* project;
    project->addName("abc");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

结果:

ABC

该计划意外完成.

c++ string class

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

标签 统计

c++ ×1

class ×1

string ×1