小编Liu*_*Hao的帖子

"函数最外层的局部变量可能不使用与任何参数相同的名称"是什么意思?

我一直在阅读C++入门第5版.在第6.1章的函数参数列表的第三段中.它写道" 此外,函数最外层的局部变量可能不会使用与任何参数相同的名称 ".这是什么意思?

我不是母语为英语的人.我不明白函数"最外层范围"的实际含义.

c++ parameters scope local-variables

12
推荐指数
3
解决办法
1244
查看次数

for 循环中的 C++ 参考

正如下面代码的for循环中一样,为什么我们必须使用reference( &c)来改变c. 为什么我们不能只在循环c中使用for。也许这是关于参数和参数之间的区别?

#include "stdafx.h"
#include<iostream>
#include<string>

using std::string;
using std::cout;
using std::cin;
using std::endl;
int main()
{
    string s1("Hello");
        for (auto &c : s1)
            c = toupper(c);
            cout << s1 << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ loops for-loop reference

5
推荐指数
2
解决办法
5363
查看次数

Scope Bound Resource Management(SBRM)是什么意思?

这些天我一直在学习C++,有时我听说过"范围界限资源管理"这个术语.Scope Bound Resource Management意味着什么?

c++

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

C++ string :: size_type错误

我正在使用visual studio 2013社区来学习c ++入门.我遇到了这个问题.当我编写以下代码时,VS显示len未定义.

#include "stdafx.h"
#include<iostream>
#include<string>

using std::string;
using std::cout;
using std::cin;
using std::endl;
int main()
{
    string line;
    while (getline(cin, line))
        if (line.size() > 10)
            auto len = line.size();
            cout << line.size() <<" "<<len <<endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我编写以下代码时,VS显示len已定义并且运行良好.

#include "stdafx.h"
#include<iostream>
#include<string>

using std::string;
using std::cout;
using std::cin;
using std::endl;
int main()
{
    string line("fewogwewjgeigeoewggwe");
            auto len = line.size();
            cout << line.size() <<" "<< len <<endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我真的没有看到它的原因.希望得到一些好的解释.多谢!!!

c++

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

什么是正则表达式[^\s]*?意思?

我开始学习python spider在网上下载一些图片,我发现代码如下.我知道一些基本的正则表达式.我知道\.jpg手段.jpg|手段or.[^\s]*?第一行的含义是什么?我想知道为什么要使用\s?两个正则表达式之间有什么区别?

http:[^\s]*?(\.jpg|\.png|\.gif)
http://.*?(\.jpg|\.png|\.gif)
Run Code Online (Sandbox Code Playgroud)

python regex

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

关于C++中的逗号运算符

我一直在使用VS 2013社区学习C++入门.当我测试以下两个程序时.我很困惑因为我认为输出应该是同样的东西.为什么结果不同?第一个如下.

#include "stdafx.h"
#include<iostream>
#include<vector>

using std::vector;
using std::cout;
using std::cin;
using std::endl;
int main()
{
    vector<int> ivec(10,0);
    vector<int>::size_type cnt =ivec.size();
    for (vector<int>::size_type ix = 0; ix != ivec.size(); ++ix)
    {
        --cnt;
        ivec[ix] = cnt;
        cout << ivec[ix] <<" "<<cnt<< endl;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

第二个程序如下.

#include "stdafx.h"
#include<iostream>
#include<vector>

using std::vector;
using std::cout;
using std::cin;
using std::endl;
int main()
{
    vector<int> ivec(10,0);
    vector<int>::size_type cnt =ivec.size();
    for (vector<int>::size_type ix = 0; ix != ivec.size(); ++ix, --cnt)
    {
        ivec[ix] = …
Run Code Online (Sandbox Code Playgroud)

c++

-2
推荐指数
1
解决办法
71
查看次数

标签 统计

c++ ×5

for-loop ×1

local-variables ×1

loops ×1

parameters ×1

python ×1

reference ×1

regex ×1

scope ×1