下限错误(Lower bound error)
我在C ++中关注
Lower_bound()
本教程。 我做了一个简单的代码,在向量中找到一个小于或等于向量中的数字的数字+我想要的任何数字。 我的代码是这样的cout << *lower_bound(A.begin(), A.end(), A[x] + 3);
向量
A[]
的排序位置。 但是代码将它指向一个大于两个数字之和的数字。例如,如果我的向量的值为
0, 3, 5, 8, 12
并且我希望它打印最小的数字小于或等于A[3] + 3 = 11
它应该输出为8
但它给出了输出12
。 有什么理由?这是我的代码:
#include <bits/stdc++.h> using namespace std; int main() { vector<int> A = {0, 5, 3, 12, 8}; sort(A.begin(), A.end()); cout << "A[3] = " << A[3] << endl; cout << *lower_bound(A.begin(), A.end(), A[3] + 3) << endl; return 0; }
I am following this tutorial on
Lower_bound()
in C++. I have made a simple code to find a number in a vector lesser than or equal to a number from the vector + any number that I want. My code goes like thiscout << *lower_bound(A.begin(), A.end(), A[x] + 3);
where the vector
A[]
is sorted. But the code points it to a number greater than the sum of both the numbers.For example if my vector has values as
0, 3, 5, 8, 12
and I want it to print the nearest number lesser than or equal toA[3] + 3 = 11
it should give output as8
but it gives the output of12
. Any reasons?Here is my code:
#include <bits/stdc++.h> using namespace std; int main() { vector<int> A = {0, 5, 3, 12, 8}; sort(A.begin(), A.end()); cout << "A[3] = " << A[3] << endl; cout << *lower_bound(A.begin(), A.end(), A[3] + 3) << endl; return 0; }
原文:https://stackoverflow.com/questions/49935249
最满意答案
我已经设法通过使用extract-text-webpack-plugin和style-ext-html-webpack-plugin的组合来解决我的难题。让我们假设一个文件夹结构如下:
|- src |- index.ejs |- inline.css |- main.css |- main.js
main.js包含以下内容:
import _ from 'lodash'; import './inline.css'; import './main.css'; function component() { const element = document.createElement('div'); element.innerHTML = _.join(['Hello', 'Webpack', '!!!'], ' '); return element; } document.body.appendChild(component());
目的是让Webpack生成dist / index.html并直接在index.html的结果头中渲染inline.css。 进一步的main.css通过css-loader加载。
为此,我创建了webpack.config.js ,如下所示:
const path = require('path'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const StyleExtHtmlPlugin = require('style-ext-html-webpack-plugin'); const extractSplashCSS = new ExtractTextPlugin('splash.css'); const extractMainCSS = new ExtractTextPlugin('main.css'); module.exports = { entry: { main: './src/main.js' }, output: { path: path.join(process.cwd(), 'dist'), filename: '[name].bundle.js' }, module: { rules: [ { include: [ path.join(process.cwd(), 'src/inline.css') ], test: /\.css$/, loaders: extractSplashCSS.extract({ use: 'css-loader' }) }, { exclude: [ path.join(process.cwd(), 'src/inline.css') ], test: /\.css$/, loaders: extractMainCSS.extract({ use: 'css-loader' }) } ] }, plugins: [ extractSplashCSS, extractMainCSS, new HtmlWebpackPlugin({ title: 'Hello Webpack 2', template: 'src/index.ejs', filename: 'index.html' }), new StyleExtHtmlPlugin('splash.css') ] };
生成的index.html包含inline.css作为index.html头部的样式标记嵌入:
<html> <head> <title>Hello Webpack 2</title> <style>body { background-color: lightgrey; }</style><link href="main.css" rel="stylesheet"></head> <body> <p>Webpack 2...</p> <script type="text/javascript" src="main.bundle.js"></script></body> </html>
I have managed to resolve my puzzle by using a combination of the extract-text-webpack-plugin and style-ext-html-webpack-plugin Let's assume a folder structure as follows:
|- src |- index.ejs |- inline.css |- main.css |- main.js
main.js contains the following:
import _ from 'lodash'; import './inline.css'; import './main.css'; function component() { const element = document.createElement('div'); element.innerHTML = _.join(['Hello', 'Webpack', '!!!'], ' '); return element; } document.body.appendChild(component());
The aim is to have Webpack generate dist/index.html and render inline.css directly in the resulting head of index.html. Further main.css loads via the css-loader.
To achieve this, I created webpack.config.js as follows:
const path = require('path'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const StyleExtHtmlPlugin = require('style-ext-html-webpack-plugin'); const extractSplashCSS = new ExtractTextPlugin('splash.css'); const extractMainCSS = new ExtractTextPlugin('main.css'); module.exports = { entry: { main: './src/main.js' }, output: { path: path.join(process.cwd(), 'dist'), filename: '[name].bundle.js' }, module: { rules: [ { include: [ path.join(process.cwd(), 'src/inline.css') ], test: /\.css$/, loaders: extractSplashCSS.extract({ use: 'css-loader' }) }, { exclude: [ path.join(process.cwd(), 'src/inline.css') ], test: /\.css$/, loaders: extractMainCSS.extract({ use: 'css-loader' }) } ] }, plugins: [ extractSplashCSS, extractMainCSS, new HtmlWebpackPlugin({ title: 'Hello Webpack 2', template: 'src/index.ejs', filename: 'index.html' }), new StyleExtHtmlPlugin('splash.css') ] };
The resulting index.html contains inline.css embedded as a style tag in the head of index.html:
<html> <head> <title>Hello Webpack 2</title> <style>body { background-color: lightgrey; }</style><link href="main.css" rel="stylesheet"></head> <body> <p>Webpack 2...</p> <script type="text/javascript" src="main.bundle.js"></script></body> </html>
相关问答
更多-
您正在将LESS文件导入到SCSS文件中,在此处: @import "../assets/css/theme.css"; @import "../assets/css/custom.css"; @import "../assets/css/variables.less"; 如果你想导入variables.less ,那么你需要首先将它编译成CSS(如果它是一个Bootstrap文件,那么我确信.css已经存储在某个地方)。 You are importing a LESS file into an SCS ...
-
要修复“ 未捕获错误:预期'样式'为字符串数组 ”,您需要使用样式而不是StyleUrls,因为StyleUrls需要简单的CSS文本。 尝试这样的一些 styles: [require('./dashboard.component.css').toString()] 在插件下,您需要根据最新版本的角度更改配置。请参阅以下代码。 plugins: [ new webpack.ContextReplacementPlugin( // The (\\|\/) pi ...
-
如果您需要prod上的模板缩小,则应该在webpack.prod.config.js (第109行)中添加以下代码: loaders: ['raw-loader', 'html-minify-loader'], 安装html-minify-loader loader: npm install html-minify-loader --save-dev 并添加指定最小化选项, 如文档中所述 : 'html-minify-loader': { empty: true, // KEE ...
-
我已经设法通过使用extract-text-webpack-plugin和style-ext-html-webpack-plugin的组合来解决我的难题。让我们假设一个文件夹结构如下: |- src |- index.ejs |- inline.css |- main.css |- main.js main.js包含以下内容: import _ from 'lodash'; import './inline.css'; import './main.css'; function ...
-
在本地计算机上运行端口8080上的其他内容,请更改package.json文件端口 "scripts": { "start": "webpack-dev-server --inline --progress --port 4200", "test": "karma start", ... On your local machine run something else on port 8080, please change in your package.json file port "scripts": ...
-
Error.stack由V8生成,它对源映射一无所知,但是如果你做console.log(error) DevTools将使用源映射替换引用,但zone.js包装原始错误并将堆栈提取为字符串,因此DevTools不能更换引用。 您可以尝试使用像sourcemapped-stacktrace这样的堆栈跟踪映射器。 Error.stack is generated by V8, which knows nothing about source maps, however if you do console.lo ...
-
我找到了一个这样做的库: https://github.com/Automattic/juice 它工作得很好,虽然它不使用我喜欢的webpack。 I found a library that does this: https://github.com/Automattic/juice It works perfectly, though it doesn't use webpack which I prefer.
-
答案非常简单。 我必须将webpack.dev.config.js中的devServer替换为以下内容 devServer: { port: 7777, historyApiFallback: true }, 这工作时本地运行,但部署到天青时,我需要下面的web.config当然,一旦我发布问题,我就会弄明白。 问题是我需要在我的入口点模块boot.browser.ts中导入style.scss。 这也回答了关于webpack如何知道只编译styles.scss而不是所有bootstrap.scss文件的问题。 Of course, as soon as I post the question, I figure it out. The issue was that I needed to import the style.scss in my entry point modu ...添加/之前的images 。 所有路径都是相对于root的,因为你的SPA是index.html位于root中,我假设。 如果没有,请在添加基本网址
另外,检查您是否正在webpack中正确复制资产: const CopyWebpackPlugin = require('copy-webpack-plugin'); plugins[ ..., new CopyWebpackPlugi ... 相关文章
更多- eclipse里报:An internal error occurred during:
- The connection to adb is down, and a severe error has occured.
- solr error logs org.apache.solr.common.SolrException: ERROR: [doc=17] unknown field alias
- Solr安装异常:SolrException: Error loading class 'solr.VelocityResponseWriter'
- error C2668: 'M' : ambiguous call to overloaded function
- win8安装VirtualBox-4.2.18提示Installation failed!error:系统找不到指定的路径
- Hadoop 异常记录 ERROR: org.apache.hadoop.hbase.MasterNotRunningException: Retried 7 times
- 命令行运行Hbase: Session 0x0 for server null, unexpected error
- solr 4.4 Error filterStart 问题
- [Hadoop] Error: JAVA_HOME is not set
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。