我正在尝试创建一个架构子文档,但出现上面列出的错误,有问题的架构看起来像这个 Schema cassuing issues
const mongoose = require('mongoose');
const Schema = mongoose.Schema
const CharacterSchema = new Schema();
CharacterSchema.add({
name: {
type: String,
required: true
},
title: {
type: String
},
charcterClass: { // will be limited in form creation
type: String
},
level: {
type: Number
}
});
const Charcter = mongoose.model('User', CharacterSchema);
module.exports = Charcter;
Run Code Online (Sandbox Code Playgroud)
架构调用架构上面
const mongoose = require ('mongoose');
const Schema = mongoose.Schema;
const {CharacterSchema} = require(__dirname +'/CharacterModel.js');
const UserSchema = new Schema()
UserSchema.add({
name: {
type: …Run Code Online (Sandbox Code Playgroud) 我无法将 a 转换char为 an int,我不知道为什么。
我只是想将从 CSV 解析的一些数据转换string为int,编译器不会让我转换。
我收到此错误:
从类型 '__gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> > >::value_type {aka std::__cxx11::basic_string<char>}' 到类型 'int' 的无效转换
注意我也试过:
static_cast<int>(data[2]);
Run Code Online (Sandbox Code Playgroud)
乃至
'a' - data[2];
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?我觉得我已经做了一百万次了。
time_t startDate;
string ID;
int beds;
int numDays;
string token;
vector<string> data;
for(int i = 0; i < 2; i++){ // run through the rest of the file
getline(customers, line);
stringstream s(line); // to parse the csv
while(getline(s,token, ',')){
data.push_back(token);
}
startDate = changeToInt(data[0]);
ID = data[1];
---> …Run Code Online (Sandbox Code Playgroud)