小编Fru*_*uDe的帖子

在 C++ 中使用“+”进行整数变量和字符串连接的非常基本的问题

我是 C++ 新手,这个问题对很多人来说可能看起来微不足道,但请记住,我刚刚开始学习 C++ 语言。

我已将一个变量分配x给 equal20并想将它与一个字符串连接起来。我的 C++ 代码如下。

#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main() {
  int x = 20;
  int y = 15;
  if (x >= y) {
    cout << x + " is greater than " + y;
  }
}
Run Code Online (Sandbox Code Playgroud)

我的预期结果是20 is greater than 15,但结果却有些奇怪é@。我很困惑,我在 GeeksForGeeks、w3schools 或 SO 的其余部分找不到解决方案。

我知道使用cout << x << " is greater than " << y;效果很好,但我不确定为什么连接在这里不起作用。另外,为什么这些奇怪的字符会出现?

提前致谢。

(另外,请不要不回答这个问题留下一个答案。我记得开始的时候JS我问一个问题,唯一的答案是“不使用document.write …

c++ string int concatenation

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

为什么常见网站的 HTML/CSS/Javascript 代码如此复杂?

这是一个例子。这是 Google.com 源代码的第一行:

<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta charset="UTF-8"><meta content="origin" name="referrer"><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><meta content="origin" name="referrer"><title>Google</title><script nonce="XjiG6ei3xpCzqSyqDw5UMQ==">(function(){window.google={kEI:'FVDQXsDdKIKJytMPnLiC2Aw',kEXPI:'31',u:'bec65bdf',kBL:'_A-L'};google.sn='webhp';google.kHL='en';})();(function(){google.lc=[];google.li=0;google.getEI=function(a){for(var c;a&&(!a.getAttribute||!(c=a.getAttribute("eid")));)a=a.parentNode;return c||google.kEI};google.getLEI=function(a){for(var c=null;a&&(!a.getAttribute||!(c=a.getAttribute("leid")));)a=a.parentNode;return c};google.ml=function(){return null};google.time=function(){return Date.now()};google.log=function(a,c,b,d,g)

线条如此,线条,线条……这是为什么呢?谷歌似乎只是一个搜索引擎,它真的需要这么多 Javascript 才能工作吗?

滚动浏览时,大约 96% 的代码是 Javascript。我的猜测是大部分代码用于连接到 cookie、广告等,但我想对此进行验证。在这种情况下,Javascript 还用于什么?

此外,一行代码平均至少跨越 15 列。为什么谷歌不把东西隔开?是为了让事情更紧凑吗?

function a(){var b=c,e=document.fonts.load(b+" 10pt "+font);google.wf&&e.then(function(){google.wf["e"+b]=Math.round(window.performance.now())})};if(document.fonts&&document.fonts.load)for(var d=l.split(","),f=0,c=void 0;c=d[f];++f)a();})();</script><div id="cst"><style>.z1asCe{display:inline-block;fill:currentColor;height:24px;line-height:24px;position:relative;width:24px}.z1asCe svg{display:block;height:100%;width:100%}.spch-dlg{background:transparent;border:none}.spch{background:#fff;height:100%;left:0;opacity:0;overflow:hidden;position:fixed;text-align:left;top:0;visibility:hidden;width:100%;z-index:10000;transition:visibility 0s linear 0.218s,background-color 0.218s}.close-button{background:none;border:none;color:#777;cursor:pointer;font-size:26px;right:0;height:11px;line-height:15px;margin:15px;opacity:.6;padding:0;position:absolute;top:0;width:15px;z-index:10}.close-button:hover{opacity:.8}.close-button:active{opacity:1}.spchc{display:block;height:42px;position:absolute;pointer-events:none}.inner-container{height:100%;opacity:.1;pointer-events:none;width:100%;transition:opacity .318s ease-in}.s2ml .inner-container,.s2ra .inner-container,.s2er .inner-container{opacity:1;transition:opacity 0s}.text-container{pointer-events:none}.s2fp-h …

html javascript css jquery

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

标签 统计

c++ ×1

concatenation ×1

css ×1

html ×1

int ×1

javascript ×1

jquery ×1

string ×1