我遇到了一个错误,说 std::size() 不是 std 的成员。然后我找到了这个链接:Why std::size() is not a member of std in gcc 8.2.0最终,我的代码在使用 . 编译文件后运行良好g++ -std=c++17 myFile.cpp。现在,我g++ -std=c++17 6.cpp -o - 6.out按照前面的链接的建议进行了尝试,但没有成功。任何意见?
码:
local ipairs = ipairs -- why set this ipairs as local?
local Access = {}
function Access.find_access_tag(source,access_tags_hierarchy)
for i,v in ipairs(access_tags_hierarchy) do
local tag = source:get_value_by_key(v)
if tag then
return tag
end
end
return nil
end
return Access
Run Code Online (Sandbox Code Playgroud)
我还没有看到将ipairs定义为本地的。我试图从互联网上找到它,但是没有发现任何有用的东西。任何意见,不胜感激。
添加.h:
int add(int x, int y); // function prototype for add.h -- don't forget the semicolon!
Run Code Online (Sandbox Code Playgroud)
为了在 main.cpp 中使用这个头文件,我们必须 #include 它(使用引号,而不是尖括号)。
主要.cpp:
#include <iostream>
#include "add.h" // Insert contents of add.h at this point. Note use of double quotes here.
int main()
{
std::cout << "The sum of 3 and 4 is " << add(3, 4) << '\n';
return 0;
}
Run Code Online (Sandbox Code Playgroud)
添加.cpp:
#include "add.h"
int add(int x, int y)
{
return x + y;
}
Run Code Online (Sandbox Code Playgroud)
嗨,我想知道,为什么我们在文件 add.cpp 中有#include“add.h”?我认为没有必要。
我的目标是提示用户输入消息/句子,然后使用将其打印在屏幕上getline()。以下是我尝试过的两种不同尝试。
第一次尝试:
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
int main(){
chat message[80];
cout << "\n what is your message today?" << endl;
cin.getline( message, 80); // Enter a line with a max of 79 characters.
if( strlen( message) > 0) // If string length is longer than 0.
{
for( int i=0; message[i] != '\0'; ++i)
cout << message[i] << ' ';
cout << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
第二次尝试:
#include <iostream>
#include <iomanip>
#include <cstring>
using …Run Code Online (Sandbox Code Playgroud) 以下是代码。
Account savings("Mac, Rita",654321, 123.5);
Account *ptrAccount = &savings;
Run Code Online (Sandbox Code Playgroud)
这Account是一个自定义类,其中包含三个用于数据成员的字段,即帐户持有人姓名,帐号,帐户余额。我知道第一行将创建一个对象并初始化数据成员的字段。第二行将创建一个名为name的指针ptrAccount。据我了解,它指向&savings,是的地址savings。在此,储蓄是科目类型的对象。在教程中,它说了类似“ ptrAccount初始化指针,使其指向对象savings”之类的内容。我错过了什么?任何意见,不胜感激。
我正在读《 c ++的完整指南》这本书。我认为第252页有错字。因此,我有以下三个文件。
在文件account.h中,
// account.h
// Defining the class Account. class definition (methods prototypes) is usually put in the header file
// ---------------------------------------------------
#ifndef _ACCOUNT_ // if _ACCOUNT_ is not defined
#define _ACCOUNT_
#include <iostream>
#include <string>
using namespace std;
class Account
{
private:
string name;
unsigned long nr;
double balance;
public: //Public interface:
bool init( const string&, unsigned long, double);
void display();
};
#endif
// _ACCOUNT_
Run Code Online (Sandbox Code Playgroud)
在account.cpp文件中,
// account.cpp
// Defines methods init() and display().
// ---------------------------------------------------
#include …Run Code Online (Sandbox Code Playgroud)