+ Reply to Thread
Results 1 to 5 of 5

Thread: Cowsay C++ version !

  1. #1
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Cowsay C++ version !

    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;
    }

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Gew's Avatar
    Gew
    Gew is offline Newbie
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Re: Cowsay C++ version !

    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

  4. #3
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Cowsay C++ version !

    Quote Originally Posted by Gew View Post
    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
    I have no idea why it might not work for you, am not the creator, just a friend that forwarded it to here.

  5. #4
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Cowsay C++ version !

    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.

    Code:
    g++ test.exe -o cowsay.cpp
    OR
    Code:
    gcc test.exe -o cowsay.cpp -lstdc++
    Wow I changed my sig!

  6. #5
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Cowsay C++ version !

    Quote Originally Posted by ZekeDragon View Post
    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.

    Code:
    g++ test.exe -o cowsay.cpp
    OR
    Code:
    gcc test.exe -o cowsay.cpp -lstdc++
    Yes, didn't see he did it wrong

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 01-26-2009, 11:14 AM
  2. Cowsay !
    By Turk4n in forum Classes and Code Snippets
    Replies: 0
    Last Post: 01-03-2009, 10:14 AM
  3. Replies: 1
    Last Post: 01-29-2008, 11:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts