I want to learn from the new C ++, so I will look at the <C ++ University tutorial> from the beginning.
Run the shuffling example in Chapter 1 and compile several exceptions, such as the question and the header file time. h.
Fatal error c1083: cannot open include file: 'stdlib ': no such file or directory
In C ++, stdlib should be changed to cstdlib, and time should be changed to ctime.
The result is abnormal when the SETW () method is used. It turns out that STD: SETW (INT); W should be in lower case.
Record the compiled source program for future reference:
# Include <iostream>
# Include <iomanip>
# Include <cstdlib>
# Include <ctime>
Using namespace STD;
Void shuffle (INT [] [13]);
Void deal (const int [] [13], const char * [], const char * []);
Int main (){
Const char * suit [4] = {"Hearts", "diamonds", "clubs", "Spades "};
Const char * face [13] = {"Ace", "Deuce", "three", "four", "five", "Six", "Seven ", "Eight", "Nine", "Ten", "Jack", "Queen", "King "};
Int deck [4] [13] = {0 };
Srand (time (0 ));
Shuffle (deck );
Deal (deck, face, suit );
Return 0;
}
Void shuffle (INT wdeck [] [13]) {
Int row, column;
For (INT card = 1; card <= 52; card ++ ){
Do {
Row = rand () % 4;
Column = rand () % 13;
} While (wdeck [row] [column]! = 0 );
Wdeck [row] [column] = card;
}
}
Void deal (const int wdeck [] [13], const char * wface [], const char * wsuit []) {
For (INT card = 1; card <= 52; card ++ ){
For (int row = 0; row <= 3; row ++ ){
For (INT column = 0; column <= 12; column ++ ){
If (wdeck [row] [column] = card ){
Cout <STD: SETW (5) <setiosflags (IOs: Right)
<Wface [column] <""
<SETW (8) <setiosflags (IOs: left)
<Wsuit [row]
<(Card % 2 = 0? '/N':'/t ');
}
}
}
}
}