C++:STRING函数返回十六进制值而不是字符串
C++: STRING Function returns hexadecimal value instead of string
在我学习C++的第二个月里,我做到了:STRING类型的功能,用于从两个用户输入的菜肴中建立和返回菜单(在VisualStudio2013中编译并运行(
#include "../../std_lib_facilities.h"
string LeMenu(string meal, string dessert) //a F() concatenates 2 strings
{
return meal, dessert; //also tried meal+dessert
}
int main()
{
string course1, course2;
cout << "What is your chice today Sir?n";
cin >> course1 >> course2; //request to input meals
LeMenu(course1,course2);
cout << "Is " << LeMenu << " ok?n"; //here we output
keep_window_open();
}
但它总是返回十六进制值,我不知道为什么:(在VisualStudio2013中编译并运行(
Is 012D15CD ok?
而不是JamEggs可以吗?(举个例子(
据我所知,我不明白为什么,我的课本甚至没有暗示这是一个可能的问题,我在互联网上也找不到任何暗示!。这不仅仅是解决问题的一种方法,如果能理解这是否是预期的mssbehavior,那就太好了。谢谢大家!
您正在打印LeMenu
的函数地址。试试这个:
cout << "Is " << LeMenu(course1, course2) << " ok?n";
请注意,你所返回的可能不是你想要的:
return meal, dessert; //Only returns dessert
你可能想要:
return meal + dessert;
cout << "Is " << LeMenu << " ok?n";
正在打印函数LeMenu()
的地址,而不是返回的字符串。要打印返回的字符串,您需要调用以下函数:
cout << "Is " << LeMenu(course1,course2) << " ok?n";
还有
string LeMenu(string meal, string dessert) //a F() concatenates 2 strings
{
return meal, dessert; //also tried meal+dessert
}
不会返回连接字符串。它使用逗号运算符,并且只返回字符串dessert
。您需要包含<string>
标头,然后可以使用类似的+
运算符
return meal + dessert;
在中
cout << "Is " << LeMenu << " ok?n";
打印函数的地址。
你想要
cout << "Is " << LeMenu(course1, course2) << " ok?n";
相关文章:
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 如何将一个ostringstream十六进制字符串字符对转换为单个unit8t等价的二进制值
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 指向存储在字符串 c++ 中的十六进制
- 如何在C++中将十六进制字符串转换为文本数据
- 使用 sprintf 将十六进制0xAABBCC转换为字符串"AA:BB:CC"
- 定义宏以将前缀 0x 添加到十六进制字符串文本
- 如何使用 setfill 和 setw 在字符串变量中存储十六进制值
- 将字符串(可以是十进制字符串或十六进制字符串)转换为整数C++
- 在Arduino中将字符串转换为(逗号分隔的十六进制)字符串到无符号字符数组
- 将 std::string( "x3BxDEx7C" ) 转换为可读的十六进制字符串?
- C++ 将十六进制字符串表示形式转换为十六进制字符串表示形式
- 字符数组到十六进制字符串的转换 - 意外输出
- C++将 wwn 字符串转换为识别为十六进制的数据类型
- 将字符串存储为十六进制而不进行转换
- C++:格式化包含十六进制值的字符串
- 字符串十六进制到指针获取值
- 如何从字符串十六进制中获取十进制
- Arduino:将字符串十六进制"#FFFFFF"转换为 3 int