Hey guys I found a C++ version of Cowsay so enjoy !
Also credit goes to the creator !
C++ pastebin - collaborative debugging tool
Code:#include <iostream> #include <string> class Cowsay { public: Cowsay() : cowsay(""), dashLength(""){} ~Cowsay(){} void printCow() { using namespace std; cout << "--" << dashLength << "--" << endl; cout << "< " << cowsay << " >" << endl; cout << "--" << dashLength << "--" << endl; cout << " | ^__^" << endl; cout << " - (oo)|_______" << endl; cout << " (__)| )/|/" << endl; cout << " ||----w |" << endl; cout << " || ||" << endl; } void getInput(const int &argc, char **argv) { for(int i=1;i<argc;i++){ cowsay+=(std::string)argv[i]; int lenArgv = strlen(argv[i]); for(int j=0;j<lenArgv;j++) dashLength+="-"; if(i+1<argc){ cowsay+=" "; dashLength+="-"; } } } private: std::string cowsay; std::string dashLength; }; int main(int argc, char* argv[]){ Cowsay cowsay; cowsay.getInput(argc, argv); cowsay.printCow(); return 0; }
A simple 'gcc.exe -o test.exe cowsay.c' did not work on MinGW/Win32! ;(
Code:C:\prog\MinGW\bin>gcc -o test.exe feww.c feww.c:1:20: iostream: No such file or directory feww.c:2:18: string: No such file or directory feww.c:4: error: syntax error before "Cowsay" feww.c:4: error: syntax error before '{' token feww.c: In function `printCow': feww.c:11: error: `using' undeclared (first use in this function) feww.c:11: error: (Each undeclared identifier is reported only once feww.c:11: error: for each function it appears in.) feww.c:11: error: syntax error before "namespace" feww.c:12: error: `cout' undeclared (first use in this function) feww.c:12: error: `dashLength' undeclared (first use in this function) feww.c:12: error: `endl' undeclared (first use in this function) feww.c:13: error: `cowsay' undeclared (first use in this function) feww.c: At top level: feww.c:21: error: syntax error before '&' token feww.c: In function `getInput': feww.c:23: error: 'for' loop initial declaration used outside C99 mode feww.c:23: error: `argc' undeclared (first use in this function) feww.c:24: error: `cowsay' undeclared (first use in this function) feww.c:24: error: `std' undeclared (first use in this function) feww.c:24: error: syntax error before ':' token feww.c:25: error: `argv' undeclared (first use in this function) feww.c:26: error: 'for' loop initial declaration used outside C99 mode feww.c:27: error: `dashLength' undeclared (first use in this function) feww.c: At top level: feww.c:34: error: syntax error before ':' token feww.c: In function `main': feww.c:41: error: `Cowsay' undeclared (first use in this function) feww.c:41: error: syntax error before "cowsay" feww.c:42: error: `cowsay' undeclared (first use in this function) feww.c:45:2: warning: no newline at end of file
You have to use g++ or include the C++ standard libraries... you've also got to name it ".cpp" instead of ".c" or gcc will assume it's a C source file.
ORCode:g++ test.exe -o cowsay.cpp
Code:gcc test.exe -o cowsay.cpp -lstdc++
Wow I changed my sig!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks