Skip to content

Commit 6b28d0c

Browse files
Updated C++ version with error checking
1 parent 1cec468 commit 6b28d0c

File tree

8 files changed

+289
-77
lines changed

8 files changed

+289
-77
lines changed

Cpp/example1-c++98.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ int main(){
2121
DeleteImage(imageReference->image);
2222
}else{
2323
cerr << "Error: ";
24-
for(int i = 0; i < errorMessage.string->size(); i++){
25-
cerr << errorMessage.string[i];
24+
for(int i = 0; i < errorMessage->string->size(); i++){
25+
wcerr << errorMessage->string->at(i);
2626
}
2727
cerr << endl;
2828
}

Cpp/example1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ int main(){
1919
DeleteImage(imageReference->image);
2020
}else{
2121
cerr << "Error: ";
22-
for(char c : errorMessage.string){
23-
cerr << c;
22+
for(wchar_t c : *errorMessage->string){
23+
wcerr << c;
2424
}
2525
cerr << endl;
2626
}

Cpp/example2-c++98.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ int main(){
3939
DeleteImage(imageReference->image);
4040
}else{
4141
cerr << "Error: ";
42-
for(int i = 0; i < errorMessage.string->size(); i++){
43-
cerr << errorMessage.string[i];
42+
for(int i = 0; i < errorMessage->string->size(); i++){
43+
wcerr << errorMessage->string->at(i);
4444
}
4545
cerr << endl;
4646
}

Cpp/example2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ int main(){
3737
DeleteImage(imageReference->image);
3838
}else{
3939
cerr << "Error: ";
40-
for(char c : errorMessage.string){
41-
cerr << c;
40+
for(wchar_t c : *errorMessage->string){
41+
wcerr << c;
4242
}
4343
cerr << endl;
4444
}

Cpp/example3.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "pbPlots.hpp"
22
#include "supportLib.hpp"
33

4+
using namespace std;
5+
46
int main(){
57
bool success;
68
StringReference *errorMessage = new StringReference();
@@ -50,7 +52,7 @@ int main(){
5052
DeleteImage(imageReference->image);
5153
}else{
5254
cerr << "Error: ";
53-
for(char c : errorMessage.string){
55+
for(wchar_t c : *errorMessage->string){
5456
cerr << c;
5557
}
5658
cerr << endl;

Cpp/make.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ g++ -c example2-c++98.cpp -std=c++98 -O3 -march=native
55
g++ -c example2.cpp -std=c++11 -O3 -march=native
66
g++ -c example1.cpp -std=c++11 -O3 -march=native
77
g++ -c example2.cpp -std=c++11 -O3 -march=native
8+
g++ -c example3.cpp -std=c++11 -O3 -march=native
89
g++ example1.o pbPlots.o supportLib.o -lm -o example1
910
g++ example2.o pbPlots.o supportLib.o -lm -o example2
11+
g++ example3.o pbPlots.o supportLib.o -lm -o example3
1012
strip example1
1113
strip example2
14+
strip example3
15+
./example1
16+
./example2
17+
./example3

0 commit comments

Comments
 (0)