io - Unknown output in C++ -
I have strange output from code here I have a prime iterator:
#include & lt; Iostream & gt; #include "PrimeIterator.cpp" int main () {Prime Eater Prime (9); Std :: cout & lt; & Lt; "Prime number" & lt; & Lt; Prime.getN () & lt; & Lt; "Is" & lt; & Lt; Prime.value () & lt; & Lt; Std :: endl; Std :: cout & lt; & Lt; "Next Principal Number" & lt; & Lt; "Is" & lt; & Lt; Prime.next () & lt; & Lt; "..." & lt; & Lt; Prime.next () & lt; & Lt; "..." & lt; & Lt; Prime.next () & lt; & Lt; Std :: endl; Return 0; } If I give prime.net () output to a raw, I get weird results: the next prime number is 37 ... 31 ... 29 but not 29 .. 31. ..37 (((If I put them in 3 different crude then everything is OK. Please C ++ gives me why C ++ returns ... My primer:
# include & lt; iostream & gt; # MAXPRIME defined as a 1000 square prime iterator {Private: int N: atom [maxprim], public: prime iterator (int n): en (en) {intraparmarere (n);} int MTN () Const {Return n;} Int IRR PRIM (Intenal Head Number) {if (primenumber == 2} Primerambar == 3) {return 1;} else if (primenumber & lt; = 1 || Primenumber Number% 2 == 0) {return 0;} else {for (int i = 3; i The argument evaluation command is dependent on the compiler.
Thus, in the line
std :: cout & lt; & Lt; "Next Principal Number" & lt; & Lt; "Is" & lt; & Lt; prime.next () & lt; & Lt; "..." & lt; & Lt; Prime.next () & lt; & Lt; "..." & lt; & Lt; Prime.next () & lt; & Lt; Std :: endl; prime.next () Calls can be evaluated in any order that is suitable for the compiler.
In the passing, do not implement the #include implementation file, unless you really do not know what you are doing. Many definition errors from Linker
In addition, there is no need to define continuity in the form of a macro using the #define in C ++. Instead, just define the constants, and avoid avoiding the unexpected text replacement by reading all the uppercase and below. Defined constants, in large part, what is the const .
Comments
Post a Comment