Domanda

long long x; double n;
x=long long(n);

Questo non funziona. Qual è il modo corretto?

È stato utile?

Soluzione

In any plain C / C++ compiler, in order to cast you have to use parentheses "(mytype)myvar", maybe you where confused because you required 2 separate words...

Altri suggerimenti

The obvious:

x = (long long) n;

C does not have constructors, this looks like a C++ constructor call.

In C, the syntax of a cast is a type name in parenthesis. It works as a prefix operator, changing the type of the expression to the right:

long long x = (long long) 3.14;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top