这是代码:
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdio>
int main(int argc, char *argv[]) {
const unsigned int max_chars = 100;
char buffer[max_chars];
std::cin.getline(buffer, max_chars, '\n');
unsigned int count = 0;
for (auto c : buffer) {
if (c == '\0') {
break;
}
count++;
}
std::cout << "Input: ===========" << std::endl;
std::cout << buffer << std::endl;
std::cout << "Number of chars ==" << std::endl;
std::cout << std::dec << count << std::endl;
std::cout << "==================" << std::endl;
} …Run Code Online (Sandbox Code Playgroud) 这是一个玩具示例:
object Example {
import collection.mutable
import collection.immutable.TreeSet
val x = TreeSet(1, 5, 8, 12)
val y = mutable.Set.empty ++= x
val z = TreeSet.empty ++ y
// This gives an error: unspecified parameter
// val z = TreeSet.empty() ++ y
}
Run Code Online (Sandbox Code Playgroud)
显然TreeSet.empty,TreeSet.empty()并不是一回事.引擎盖下发生了什么?我什么时候可以安全地省略(或在这种情况下不省略)括号?
我已经将一些代码发送到控制台,然后在eval上面的代码中将其删除,然后再执行以下代码:
implicit object StringOrdering extends Ordering[String] {
def compare(o1: String, o2: String) = {
o1.length - o2.length
}
}
object StringOrdering1 extends Ordering[String] {
def compare(o1: String, o2: String) = {
o2.length …Run Code Online (Sandbox Code Playgroud) 运行以下代码时,我得到了一些奇怪的结果:
object Example {
implicit object StringOrdering extends Ordering[String] {
def compare(o1: String, o2: String) = {
o1.length - o2.length
}
}
object StringOrdering1 extends Ordering[String] {
def compare(o1: String, o2: String) = {
o2.length - o1.length
}
}
import collection.mutable
import collection.immutable.TreeSet
val x = TreeSet(1, 5, 8, 12)
val y = mutable.Set.empty ++= x // mutable.Set[Int]
val y1 = mutable.Set.empty[Int] ++= x // mutable.Set[Int]
val z = TreeSet.empty ++ y // Set[Any]
val z1 = TreeSet.empty[Int] ++ y …Run Code Online (Sandbox Code Playgroud) 这是代码:
import java.security.InvalidParameterException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by IDEA on 13/06/15.
*/
public class ShiftCodes {
private final Map<byte[], Byte> shiftMap;
public ShiftCodes(int[][] collapseMatrix) {
shiftMap = new HashMap<byte[], Byte>();
for (int i = -128; i < 128; i++) {
for (int j = -128; i < 128; i++) {
byte b1 = (byte) i;
byte b2 = (byte) j;
byte[] k = new byte[] {b1, b2};
Byte v = new Byte(GenoBytes.genoByte(GenoBytes.collapse(
b1, b2, collapseMatrix)));
shiftMap.put(k, v); …Run Code Online (Sandbox Code Playgroud) 这是代码:
#include <stdlib.h>
#include <iostream>
int main() {
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std:cin >> v1 >> v2;
std::cout << "The sum of " << v1 << "and " v2 << "is " << v1+v2 << std:endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
g++ x.cpp
#x.cpp: In function ‘int main()’:
#x.cpp:23:9: error: ‘cin’ was not declared in this scope
#x.cpp:23:9: note: suggested alternative:
#In file included from x.cpp:19:0:
#/usr/include/c++/4.7/iostream:61:18: note: ‘std::cin’
#x.cpp:24:48: …Run Code Online (Sandbox Code Playgroud)