struct

Search vector of structs

China☆狼群 提交于 2021-02-11 14:01:08
问题 I'm trying to find a string within in a vector of structs. But I keep getting an error, the error message is way too long so Ill upload it externally. A part of it is "error: no match for 'operator==' (operand types are 'char' and 'const std::__cxx11::basic_string') { return *__it == _M_value; }" The code Im currently using is: struct constants { std::string name, lastname; float salary=0; }; void searchPerson(const std::vector<constants> &search) { using namespace std; vector<constants>name;

How to initialize a structure field std::map<std::string, std::string> called params

爷,独闯天下 提交于 2021-02-11 12:01:39
问题 I'm trying to initialize a structure using some data being held in a std::vector<tokens> - tokens are simply strings. My struct is: struct parsedBlock{ std::string name; std::map<std::string, std::string> params; } parsedBlock block; tokens[0] is block.name so it's simple to just write block.name = tokens[0] But the question is how to intialize a params field supposing that key is tokens[i] and value is tokens[i+1] . Thanks in advance. Greetings! 回答1: I guess your "tokens" vector contains the

How do I read data from a text file into an array of struct

南楼画角 提交于 2021-02-10 22:30:27
问题 I'm trying to read data from a text file called fields.txt which holds the members of the struct Fields . {1, 0, 7.4, 39.5, 5.33784}, {3, 1, 4.6, 27.9, 6.06522}, {5, 2, 2.2, 12.5, 5.68182}, {8, 0, 14.5, 86, 5.93103}, {11, 1, 8, 43.8, 5.475}, {16, 2, 5.9, 37.7, 6.38983}, {22, 0, 12.7, 72, 5.66929}, {24, 1, 10.5, 63.2, 6.01905} I want my program to read the data into my array of struct called Fields fielddata[8] = {}; so that I am able to use the data to create a display. #include<iostream>

How do I read data from a text file into an array of struct

最后都变了- 提交于 2021-02-10 22:30:21
问题 I'm trying to read data from a text file called fields.txt which holds the members of the struct Fields . {1, 0, 7.4, 39.5, 5.33784}, {3, 1, 4.6, 27.9, 6.06522}, {5, 2, 2.2, 12.5, 5.68182}, {8, 0, 14.5, 86, 5.93103}, {11, 1, 8, 43.8, 5.475}, {16, 2, 5.9, 37.7, 6.38983}, {22, 0, 12.7, 72, 5.66929}, {24, 1, 10.5, 63.2, 6.01905} I want my program to read the data into my array of struct called Fields fielddata[8] = {}; so that I am able to use the data to create a display. #include<iostream>

Why can this type not be resolved?

放肆的年华 提交于 2021-02-10 18:48:16
问题 I have the following code in my C header file: typedef struct mb32_packet_t { uint8_t compid; uint8_t servid; uint8_t payload[248]; uint8_t checksum; } __attribute__((packed)) mb32_packet_s; Doing the following works: struct mb32_packet_t packet; When using this: mb32_packet_t packet; I get: Type 'mb32_packet_t' could not be resolved Unknown type name 'mb32_packet_t'; use 'struct' keyword to refer to the type Isn't typedef struct intended for exactly this purpose, i.e. to be able to omit the

Why can this type not be resolved?

可紊 提交于 2021-02-10 18:46:26
问题 I have the following code in my C header file: typedef struct mb32_packet_t { uint8_t compid; uint8_t servid; uint8_t payload[248]; uint8_t checksum; } __attribute__((packed)) mb32_packet_s; Doing the following works: struct mb32_packet_t packet; When using this: mb32_packet_t packet; I get: Type 'mb32_packet_t' could not be resolved Unknown type name 'mb32_packet_t'; use 'struct' keyword to refer to the type Isn't typedef struct intended for exactly this purpose, i.e. to be able to omit the

Why can't I create an opaque data type?

时光毁灭记忆、已成空白 提交于 2021-02-10 15:56:17
问题 I'm trying to experiment with opaque data types to get an understanding of them. The main problem is that I keep getting an 'incomplete' error. main.c #include <stdio.h> #include <stdlib.h> #include "blepz.h" int main() { setfnarp(GOO,5); int loogaboo = getfnarp(GOO); printf("%i", loogaboo); return 0; } fnarpishnoop.c #include "blepz.h" struct noobza { int fnarp; }; void setfnarp(struct noobza x, int i){ x.fnarp = i; }; int getfnarp(struct noobza x){ return x.fnarp; }; blepz.h struct noobza;

Why can't I create an opaque data type?

為{幸葍}努か 提交于 2021-02-10 15:55:02
问题 I'm trying to experiment with opaque data types to get an understanding of them. The main problem is that I keep getting an 'incomplete' error. main.c #include <stdio.h> #include <stdlib.h> #include "blepz.h" int main() { setfnarp(GOO,5); int loogaboo = getfnarp(GOO); printf("%i", loogaboo); return 0; } fnarpishnoop.c #include "blepz.h" struct noobza { int fnarp; }; void setfnarp(struct noobza x, int i){ x.fnarp = i; }; int getfnarp(struct noobza x){ return x.fnarp; }; blepz.h struct noobza;

how to load Matlab's struct (saved with v7.3) in Python

谁都会走 提交于 2021-02-10 14:19:35
问题 I created a 1X20 struct in Matlab. This struct has 9 fields. The struct is saved in -v7.3 version because of its dimensions (about 3 Giga). one of the fields contains 4D matrix, other contain cell arrays, meaning it is a complex struct. I would like to know if there is a way to load this struct into Python? 回答1: MATLAB v7.3 uses HDF5 storage; scipy.io.loadmat cannot handle that MATLAB: Differences between .mat versions Instead you have to use numpy plus h5py How to read a v7.3 mat file via

Is there a way to sort structs by multiple variables in C?

﹥>﹥吖頭↗ 提交于 2021-02-10 05:44:06
问题 I have to write a function that sorts structs in an array. the struct is: #define MAX_USERNAME_LENGTH 16 typedef struct{ char username[MAX_USERNAME_LENGTH]; unsigned int rides; unsigned int rank; } driver; The program load the data from a .txt file and fills an array driver driver_list[256] I have to sort driver_list by ranks AND number of rides. So if my file contains //user rides rank frank209 3 6 john76 7 6 harry99 2 2 bob77 5 2 Output must show: john76 7 6 frank209 3 6 bob77 5 2 harry99 2