Questions tagged [auto]

The `auto` keyword was repurposed in C++11 for a deduced type. When used to replace a type name in an initialized variable declaration, the variable is given the same type as the initializer. When used as a return type, the return type is specified as a trailing return type, or deduced from the return-expression.

Consider the following code:

bool Function()
{
    return true;
}

bool result = Function();

The return type of Function is unambiguously known at compile time, so the variable declaration can be replaced with:

auto result = Function();

The type of result will thus be deduced. The auto keyword becomes very useful, when type name is long:

for (std::vector<MyNamespace::MyType>::const_iterator iter = v.cbegin(); iter != v.cend(); iter++)

C++11 allows shorter declaration:

for (auto iter = v.cbegin(); iter != v.cend(); iter++)

It is worth noting that the keyword auto changed meaning with advent of C++11 and it is almost always used in this new context.

1270 questions
-1
votes
2 answers

Confusion related to auto and static variables

#include int main(){ int a=10; { printf("%d",a); int a=20; printf("%d",a); } printf(" %d",a); return 0; } Output:10 20 10 In the above code I understand that the visibility of variable a(inside…
-1
votes
1 answer

Create a script to auto log me onto a website accessed by an IP url including the "click OK to logon"

I am trying to create a JavaScript/HTML/or C++ that will automatically press an OK button on a window when logging onto an IP via a browser. Basically, if I wanted to automatically log in to a site with a cookie filling in my username and password,…
-2
votes
1 answer

Can I use template or auto keyword in cpp to create a variable that i can use with std:: cin to get a value from user?

this line of code is wrong and won't compile but i am wondering if it can be fixed. #include template auto getValue() { std::cout << "Enter an integral value: "; T value{}; std::cin >> value; // I would do…
kitshaar
  • 11
  • 1
-2
votes
1 answer

How to access and convert pair value?

vector> alpha; for(int i = 0; i < 26; i++) { if (letter[i] > 0) { alpha.push_back(pair(letter[i], (i+'A'))); } } sort(alpha.begin(), alpha.end()); for(auto& val : alpha){ string str =…
-2
votes
1 answer

Taking inputs in unordered map from two vectors

I'm trying to take input from two different vectors into an unordered_map but getting error vector sortPeople(vector& names, vector& heights) { vector result; unordered_map mp; for (auto s :…
-2
votes
3 answers

Discord.py Fetch Message Bot

I want to fetch messages from one private discord channel to my channel. But not all messages. Just my wanted ones. Like "car" message. I want to fetch all "car" messages to my discord channel. I don't know programming at all. I'm working on it for…
StormaS
  • 33
  • 3
-2
votes
1 answer

Can't modify the value of a reference in Range based loop

I'm working on a school project of boolean minimization, and here I want to delete some elements of a set of my user defined class. This is where the error occurs: (dc and PI are both sets of my class Term, passed to this function by reference.…
hmlssslmn
  • 11
  • 2
-2
votes
2 answers

How can I print 6 numbers in ascending order without randomly overlapping the numbers?

Sharing Lotto, the largest lottery in Korea, is conducted by selecting 6 different numbers from 1 to 45. The number of sharing lotto can be selected by the buyer himself, but it can also be selected in an "automatic" way that is left to the…
-2
votes
1 answer

Auto delete files in php after time without request

php script works if someone request it right? so how i can make php script delete files after 1h for example without need to wait someone to request the script.
Scie Nce
  • 3
  • 1
-2
votes
3 answers

How to create auto iteration in for loop which would assign pointer instead of value to it

I want to create auto iteration loop like this: std::vector vector1; for(auto it : vector1) { if(&it == &vector1.at(4)) //do something... else continue; } but I found out that adress of "it" when it's equal to…
Daniel Klimek
  • 77
  • 1
  • 7
-2
votes
1 answer

Auto Assignment in BMC Remedy ITSM

I am looking for a solution to assign incidents assigned to my group to automatically get assigned to another group without any manual intervention. The auto assignment should be based on the value in Summary field. I have tried manual assignment…
-2
votes
1 answer

Full width of input field in a inline-block not working

Issue: image.png The drop-down menu is showing "Choose an option" like a box that comes out of the text area. I did my little research and it is a CSS issue and followed the instructions. I right-click on the "Choose an option" and click on…
-2
votes
1 answer

I want to automatically run 1 file Demfile.pl with crontab (Centos 7). However / var / spool / mail / root send mail to log as follows

I want to automatically run 1 file Demfile2.pl with crontab (Centos 7). However /var/spool/mail/root send mail to log as follows: DBD::SQLite::db do failed: no such table: HISTORY1 at /root/perl/test/Demfile2.pl line 31. DBD::SQLite::db do failed:…
noname
  • 7
  • 1
-2
votes
1 answer

how to fix the "speed bump" sign in windows pop up

want to implement an auto unlock credential. I used the SampleV2CredentialProvider demo, and wrote the account password in the "CSampleCredential::Initialize" as follow hr = SHStrDupW(L"mypassword", &_rgFieldStrings[SFI_PASSWORD]); and change the…
jane
  • 21
  • 2
-2
votes
1 answer

Is it possible to declare a template function with 'auto' return type as a friend of a class?

How to declare the following function as a friend of a class template inline auto func(T & val) { //return ...; } class A { friend auto func(A & val); }
Alexey Starinsky
  • 3,699
  • 3
  • 21
  • 57