我不明白为什么我的输出是 1,1 如何将其更改为 "type name" 和 "parameters" ?蒂亚
I can't understand why my output is 1,1 how can I change it to "type name" and "parameters"? TIA
我只是 c++ 的新手,我正在阅读有关函数的信息,但现在我正在尝试使用字符串,但我真的无法理解它。 如何显示输出中的"类型名称"和"参数"?这是我的代码:
#include <iostream>
using namespace std;
string f1 (string a)
{
string b;
b = " type name ";
return (b);
}
string f2 (string c)
{
string d;
d = " parameters ";
return (d);
}
int main ()
{
string x,y;
x = f1(" type name ");
y = f2(" parameters ");
cout<<"Functions is a group of statements that executed"<<endl;
cout<<"when it is called. It is consist of"<< x <<","<< y <<endl;
cout<<"and a statement. It can be called to some some point of the program."<<endl;
return 0;
}
cout<<"when it is called. It is consist of"<< f1 <<","<< f2 <<endl;
f1
和f2
是函数。你不想输出函数,你想输出调用函数的结果。
x = f1(" type name ");
y = f2(" parameters ");
您已将调用结果存储在 x
和 y
中,因此请使用它们。
cout<<"when it is called. It is consist of"<< x <<","<< y <<endl;
// ^ ^
更改此内容:
cout<<"when it is called. It is consist of"<< f1 <<","<< f2 <<endl;
对此:
cout<<"when it is called. It is consist of"<< x <<","<< y <<endl;
但是,您的代码中有冗余。
你想做什么,
string f1 (string a)
string f2 (string c)
接受一个字符串,但你没有对它做任何事情,主要是用你从未在内部使用的字符串调用函数。
您是否尝试使用,
string f1 ()
string f2 ()
并使用它
cout<<"when it is called. It is consist of"<< x <<","<< y <<endl;
您正在尝试打印字符串而不是函数
相关文章:
- 将系数存储在头文件的数组中("does not name a type"错误)
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 如何解决"'mutex' in namespace 'std' does not name a type"?
- 在 C++ 中使用命名空间时出现"does not name a type"错误
- 已声明时"Does not name a type"错误
- 嵌套类"does not name a type"
- 为什么当我的代码超出函数范围时,"does not name a type"出现编译器错误?
- 虚幻:按照教程"Unknown type name UTextRenderComponent"编译错误
- 在编辑器中"Error: type name is not allowed"消息,但不在编译期间
- C++生成器错误"Type name expected" time_t
- 头文件类成员函数声明错误:"incomplete type name in nested name specifier"
- 模板错误:非类型 ".. [with T=T] is not a type name"
- C++:声明'TYPE& name(&TYPE);'是什么意思?
- 升级 XCode 后出现"Parse issue: Unknown type name"错误
- 为什么我使用这些意大利面模板会"error: type name is not allowed"?
- 我不明白为什么我的输出是 1,1 如何将其更改为 "type name" 和 "parameters" ?蒂亚
- 双括号"[[foo()]] type name;"语法在 C++ 中的含义?
- Type** name和Type* name[]有什么区别?
- Type name = name;在c++中非常有用
- Python "type(<name>, <bases>, <dict>)"在 c++ 中的等效性是什么?