小编noy*_*o88的帖子

在 C++ 中返回映射的函数

有人可以给出一个在 C++ 中返回 map 的函数的实际例子。

我尝试了其他帖子的答案,但我不知道如何申请。

这是我的工作代码:

auto DataArray = jvalue.at(U("data")).as_array();

//Make an associative array or map with key value pair from extracted json data
std::map<int, std::string> staffMap;

// loop through 'data' object
for (int i = 0; i < DataArray.size(); i++)
{
    try
    {
        auto data = DataArray[i];
        auto dataObj = data.as_object();

        int key;
        std::string value;

        // loop through each object of 'data'
        for (auto iterInner = dataObj.cbegin(); iterInner != dataObj.cend(); ++iterInner)
        {
            auto &propertyName = iterInner->first;
            auto &propertyValue …
Run Code Online (Sandbox Code Playgroud)

c++ return function stdmap cpprest-sdk

8
推荐指数
2
解决办法
1万
查看次数

使用块颤动从屏幕 B 导航回来时如何更新屏幕 A

我有一个屏幕(A),它使用“AccountFetched”状态从数据库加载数据列表:

return BlocProvider<AccountBloc>(
      create: (context) {
        return _accountBloc..add(FetchAccountEvent());
      },
      child: BlocBuilder<AccountBloc, AccountState>(
        builder: (context, state) {
          if (state is AccountFetched) {
            accounts = state.accounts;
          }
Run Code Online (Sandbox Code Playgroud)

在我的第二个屏幕 (B) 中,我调用 AddAccountEvent 将数据添加到数据库并导航回父屏幕屏幕 (A)。

onPressed: () {
   BlocProvider.of<AccountBloc>(context)
     ..add(AddAccountEvent(account: account));
   Navigator.of(context).pop();
}
Run Code Online (Sandbox Code Playgroud)

但是当我导航回屏幕 A 时,数据列表并未更新。我应该手动刷新屏幕(A)还是如何更新块的状态?

这是我的集体课程:

class AccountBloc extends Bloc<AccountEvent, AccountState> {
  AccountBloc() : super(AccountInitial());

  @override
  Stream<AccountState> mapEventToState(AccountEvent event) async* {
    if (event is FetchAccountEvent) yield* _fetchAccountEvent(event, state);
    if (event is AddAccountEvent) yield* _addAccountEvent(event, state);
  }

  Stream<AccountState> _fetchAccountEvent(
      FetchAccountEvent event, AccountState state) async* …
Run Code Online (Sandbox Code Playgroud)

flutter bloc flutter-navigation flutter-bloc

5
推荐指数
1
解决办法
3885
查看次数

错误状态:测试尝试使用 bloc_test 和mocktail 对 T State 类型的参数使用 any 或 captureAny

我尝试了这里的解决方案https://github.com/felangel/mocktail/issues/42但仍然出现错误。这是我的代码:

class MockUserRepository extends Mock implements UserRepository {}
class MockAuthenticationBloc extends MockBloc<AuthenticationEvent, AuthenticationState> implements AuthenticationBloc {}
class FakeAuthenticationEvent extends Fake implements AuthenticationEvent {}
class FakeAuthenticationState extends Fake implements AuthenticationState {}

void main() {
  MockUserRepository mockUserRepository;
  MockAuthenticationBloc mockAuthenticationBloc;

  setUp(() {
    mockUserRepository = MockUserRepository();
    mockAuthenticationBloc = MockAuthenticationBloc();
    registerFallbackValue(FakeAuthenticationEvent());
    registerFallbackValue(FakeAuthenticationState());
  });

  group('Login', () {
    final username = 'someusername';
    final password = 'somepassword';
    final token = 'sometoken';
    final loginError = 'Some error message.';

    blocTest('emits [LoginLoading] when successful',
      build: () {
        when(() => …
Run Code Online (Sandbox Code Playgroud)

flutter bloc-test

5
推荐指数
1
解决办法
2367
查看次数

如何在c ++中使用返回类型std :: map导出函数

我在Visual c ++中有一个DLL项目和一个CLR项目.

DLL项目是导出std :: map类型函数的项目.我将从我的CLR项目中调用该函数.

来自DLL项目,staff.h

#ifdef STAFFS_EXPORTS
#define STAFFS_API __declspec(dllexport)
#else
#define STAFFS_API __declspec(dllimport)
#endif

#include <string>
#include <map>

namespace Staffs {
    // other exported functions
    ....
    //
    extern "C" STAFFS_API auto GetStaffMap() -> std::map<int, std::string>;
} 
Run Code Online (Sandbox Code Playgroud)

staff.cpp

namespace Staffs {
   std::map<int, std::string> staffMap;

   extern "C" auto GetStaffMap() -> std::map<int, std::string> {
        return staffMap;
    }

   void display_json(json::value const & jvalue, utility::string_t const & prefix)
    {
      // some code being skipped here
      .......
      //
      staffMap.insert(std::make_pair(key, value));
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试编译我的DLL项目时,我遇到了一些错误: …

c++ function stdmap

4
推荐指数
1
解决办法
434
查看次数

如何使用 Windows 操作系统在 C++ 中获取 UTC 时间偏移

我的问题很简单。如何获取菲律宾的 UTC 偏移量(+8)和日本的 UTC 偏移量(+9),并将其转换为整数。

任何建议都是很大的帮助。谢谢。

更新

为了进一步说明,我有一个 C++ 桌面应用程序,无论使用该应用程序,我都需要自动检测其时区。就像如果应用程序将在日本使用一样,将使用日本的时区偏移。那可能吗?

c++ utc timezone-offset

3
推荐指数
1
解决办法
5843
查看次数

file.getOwner() 返回“DriveUser”值,而不是 Google 应用程序脚本中文件的实际所有者

我想显示谷歌驱动器中此文件夹中的每个文件详细信息,但 .getOwner() 方法返回“DriveUser”。这些文件是由某人和我上传的。因此,如果您手动检查驱动器,您可以看到每个文件的上传者/所有者的名称。

    var folder = DriveApp.getFolderById('18MW-6bpYyqQUx9floFgdmKnKIBcd2NZhvTK');
    var files = folder.getFiles();
    while (files.hasNext()){
        file = files.next();

        Logger.log(file.getName());
        Logger.log(file.getSize());
        Logger.log(file.getOwner());
        Logger.log(file.getDateCreated());

    }
Run Code Online (Sandbox Code Playgroud)

除 getOwner() 方法外,其他文件方法返回正确的值。

javascript google-apps-script

1
推荐指数
1
解决办法
3369
查看次数

如何正确命名包括c ++中的警卫

我有3个头文件:

misc.h
MyForm.h
Registration.h
Run Code Online (Sandbox Code Playgroud)

在misc.h文件中我把

#ifndef MISC_H
#define MISC_H
#endif
Run Code Online (Sandbox Code Playgroud)

在MyForm.h中,我把

#include "misc.h"
#include "Registration.h"
Run Code Online (Sandbox Code Playgroud)

在Registration.h中,我把

#include "misc.h"
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

c++

0
推荐指数
2
解决办法
256
查看次数

如何从本地node.js连接amazon documentDB

如果我的node.js应用程序位于基于此页面的ec2实例中,我可以连接到documentDB:https://docs.aws.amazon.com/documentdb/latest/developerguide/connect_programmatically.html

但是,如果我从本地电脑运行 Node.js 应用程序,是否可以连接到 documentDb?

编辑: 这是我的一些带有示例连接字符串的代码。我使用猫鼬进行连接。

const connectionString = 'mongodb://user:password@sampledb.cluster-asdf.ap-northeast-1.docdb.amazonaws.com:27017/mydb?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false';

mongoose.Promise = bluebird;
mongoose.connect(connectionString, {
    useMongoClient: true,
    reconnectTries: 1000,
    autoReconnect: true,
    connectTimeoutMS: 99999,
  }
);
Run Code Online (Sandbox Code Playgroud)

node.js aws-documentdb

0
推荐指数
1
解决办法
4403
查看次数