int

Why char is not taken as numeral in C++?

北慕城南 提交于 2020-06-08 19:45:30
问题 I wrote a code in C, which ran perfectly, I translated it to C++ . There it was giving wrong output. I had an iteration where I used both the input and the iterator variable as char to save space. But didn't behaved as expected. unsigned char repeat, i; cin >> repeat; for(i= 0; i < repeat; i++) What is the equivalent line for scanf("%hhi", &repeat) ? 回答1: Why char is not taken as numeral in C++? Because C and C++ are different programming languages. See for example n3337, a draft C++ standard

Why char is not taken as numeral in C++?

大憨熊 提交于 2020-06-08 19:44:09
问题 I wrote a code in C, which ran perfectly, I translated it to C++ . There it was giving wrong output. I had an iteration where I used both the input and the iterator variable as char to save space. But didn't behaved as expected. unsigned char repeat, i; cin >> repeat; for(i= 0; i < repeat; i++) What is the equivalent line for scanf("%hhi", &repeat) ? 回答1: Why char is not taken as numeral in C++? Because C and C++ are different programming languages. See for example n3337, a draft C++ standard

How to convert Int to Hex String in Kotlin?

淺唱寂寞╮ 提交于 2020-06-08 04:40:33
问题 I'm looking for a similar function to Java's Integer.toHexString() in Kotlin. Is there something built-in, or we have to manually write a function to convert Int to String ? 回答1: You can still use the Java conversion by calling the static function on java.lang.Integer : val hexString = java.lang.Integer.toHexString(i) And, starting with Kotlin 1.1, there is a function in the Kotlin standard library that does the conversion, too: fun Int.toString(radix: Int): String Returns a string

How to properly instantiate os.FileMode

瘦欲@ 提交于 2020-06-07 13:47:06
问题 I have seen countless examples and tutorials that show how to create a file and all of them "cheat" by just setting the permission bits of the file. I would like to know / find out how to properly instantiate os.FileMode to provide to a writer during creation / updating of a file. A crude example is this below: func FileWrite(path string, r io.Reader, uid, gid int, perms string) (int64, error){ w, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0664) if err != nil { if path == ""

Why is “int” not working correctly with “j” but long long is working fine?

孤者浪人 提交于 2020-05-30 11:31:08
问题 This is my code with int j : void solve(){ unsigned long long n; cin>>n; unsigned long long sum = 0; int j = 1; for(int i=3;i<n+1;i+=2){ sum += ((4*i)-4)*(j); j++; } cout<<sum<<"\n"; } Input: 499993 Output: 6229295798864 but it is giving wrong output, and here is my code with long long j which is working fine: void solve(){ int n; cin>>n; unsigned long long sum = 0; long long j = 1; for(int i=3;i<n+1;i+=2){ sum += ((4*i)-4)*(j); j++; } cout<<sum<<"\n"; } Input: 499993 Output:

Why is “int” not working correctly with “j” but long long is working fine?

情到浓时终转凉″ 提交于 2020-05-30 11:29:57
问题 This is my code with int j : void solve(){ unsigned long long n; cin>>n; unsigned long long sum = 0; int j = 1; for(int i=3;i<n+1;i+=2){ sum += ((4*i)-4)*(j); j++; } cout<<sum<<"\n"; } Input: 499993 Output: 6229295798864 but it is giving wrong output, and here is my code with long long j which is working fine: void solve(){ int n; cin>>n; unsigned long long sum = 0; long long j = 1; for(int i=3;i<n+1;i+=2){ sum += ((4*i)-4)*(j); j++; } cout<<sum<<"\n"; } Input: 499993 Output:

Trying to use int in getline

↘锁芯ラ 提交于 2020-05-25 07:24:42
问题 cout << "How many questions are there going to be on this exam?" << endl; cout << ">>"; getline(cin, totalquestions); This small piece of code comes from a function in a class that I have created and I need totalquestions to be an int so that it can run through a for loop and keep asking the total amount of questions that I have asked. question q; for(int i = 0; i < totalquestions; i++) { q.inputdata(); questions.push_back(q); } Where does this piece of code comes to play? Does anyone have

Can %c be given a negative int argument in printf?

爱⌒轻易说出口 提交于 2020-05-23 11:54:08
问题 Can I pass a negative int in printf while printing through format specifier %c since while printing int gets converted into an unsigned char? Is printf("%c", -65); valid? — I tried it on GCC but getting a diamond-like character(with question-mark inside) as output. Why? 回答1: Absolutely yes, if char is a signed type. C allows char to be signed or unsigned and in GCC you can switch between them with -funsigned-char and -fsigned-char. When char is signed it's exactly the same thing as this char

Printing array of integers generates weird output in Ada

六眼飞鱼酱① 提交于 2020-05-16 05:53:06
问题 I created a simple Ada program that allows a user to populate an array with a maximum of 100 non negative and non zero integers and then prints them out. When I call the function to print out the numbers it prints them out but at the same time it also prints out a bunch of strange and seemingly random numbers. What mistake have I made in my code that is causing the program to output such strange results? This is my first time writing in Ada. For example when I populate the empty array with

pandas convert objects with numbers and nans to ints or floats

a 夏天 提交于 2020-05-15 02:40:30
问题 with the knowledge that similar cases have been answered several times I couldn't make it work anyway. sample data: 10 5 20 5 6 after i figured out that with: df = df['column_name'].astype(str).astype(int) it would work if there wasn't nans in the input data. error: invalid literal for int() with base 10: 'nan' Also I did try to use float instead but it gives an error as well error: could not convert string to float what am I missing? output can be anything with "null", "nan", "" for example: