【发布时间】:2020-03-15 09:38:04
【问题描述】:
我目前正在研究字符串并研究这个简单的示例。我正在尝试将 "birthdate" 用户输入传递到我的 logSuccess 字符串中。做了很多谷歌搜索,但还没有找到解决方案。有什么建议吗?
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
std::string birthdate;
void printString(const std::string& string)
{
std::cout << string << std::endl;
}
void getBirthdate()
{
std::cout<<"When is your birthday? "<<std::endl;
cin>>birthdate;
}
int main()
{
std::string name = std::string("Dame") + " hello!";
std::string logSuccess = std::string("Thank you! We will send you a postcard on ") + birthdate;
printString(name);
getBirthdate();
printString(logSuccess);
std::cin.get();
}
【问题讨论】:
-
想想你做事的顺序!您没有循环,因此
main函数中的代码将严格按照自上而下的方向执行。
标签: c++ string pass-by-reference