简体   繁体   English

在C ++中使用指针的语法错误

[英]Syntax Error in using pointers in C++

I'm not sure what is wrong in the syntax of my code, something wrong with returning the address location of the pointers of firstname and secondname. 我不确定我的代码语法中有什么问题,返回名字和名字的指针的地址位置有问题。

string names()
{
    string firstname;
    string secondname;

    int *p_firstname = & firstname;
    int *p_secondname = & secondname;

    cout << "Enter your first name: ";
    cin >> firstname;
    cout << "Enter your second name: ";
    cin >> secondname;

    return &p_firstname, &p_secondname;
}

Try return your two strings with a std::pair<std::string, std::string> : 尝试使用std::pair<std::string, std::string>返回两个字符串:

std::pair<std::string, std::string> names() {
    ...
    return std::make_pair(firstname, secondname);

You are trying to return two int pointer addresses? 您正在尝试返回两个int指针地址吗? as a string type? 作为字符串类型?

try 尝试

return firstname + secondname;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM