[RESOLVED] errors about types
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 28

Thread: [RESOLVED] errors about types

  1. #1
    Join Date
    Apr 2009
    Posts
    605

    [RESOLVED] errors about types

    Code:
    void write()
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            cout <<"";
    
        }
    
    
        template <typename A, typename ...B>
        void write(string argHead, B... argTail)
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            if (blnBlink==true)
            {
                CONSOLE_SCREEN_BUFFER_INFO csbi;
    
                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
                string a;
                a=argHead;
                TextBlink(a, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                COORD Position;
                Position.X=csbi.dwCursorPosition.X+strlen(a.c_str());
                Position.Y=csbi.dwCursorPosition.Y;
                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Position);
            }
    
            else
                cout << argHead;
            write(argTail...);
        }
    
    
        template <typename A, typename ...B>
        void write(char *argHead, B... argTail)
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            if (blnBlink==true)
            {
                CONSOLE_SCREEN_BUFFER_INFO csbi;
    
                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
                string a;
                a=argHead;
                TextBlink(a, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                COORD Position;
                Position.X=csbi.dwCursorPosition.X+strlen(a.c_str());
                Position.Y=csbi.dwCursorPosition.Y;
                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Position);
            }
    
            else
                cout << argHead;
            write(argTail...);
        }
    
        template <typename A, typename ...B>
        void write(A argHead, B... argTail)
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            if (blnBlink==true)
            {
                CONSOLE_SCREEN_BUFFER_INFO csbi;
    
                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
                string a;
                //the error is in next 2 lines
                a=to_string(argHead);
                TextBlink(a, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                COORD Position;
                Position.X=csbi.dwCursorPosition.X+strlen(a.c_str());
                Position.Y=csbi.dwCursorPosition.Y;
                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Position);
            }
    
            else
                cout << argHead;
            write(argTail...);
        }
    what i'm doing wrong with my write() function?
    i did like the read() function(for work diferent with another types) but i get these error:
    "C:\Users\Joaquim\Documents\CodeBlocks\My Class\console.h|218|error: call of overloaded 'to_string(char*&)' is ambiguous|"
    can anyone advice me?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,273

    Re: errors about types

    Quote Originally Posted by Cambalinho View Post
    ... i get these error:
    "C:\Users\Joaquim\Documents\CodeBlocks\My Class\console.h|218|error: call of overloaded 'to_string(char*&)' is ambiguous|"
    can anyone advice me?
    Google can it for sure!
    https://www.google.com/search?source...s%7C&gs_htsa=1
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Posts
    605

    Re: errors about types

    Quote Originally Posted by VictorN View Post
    i have tested and the problem is other
    by some reason the compiler don't call that functions correctly
    and my head is in pain
    Last edited by Cambalinho; November 6th, 2013 at 10:14 AM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,273

    Re: errors about types

    Quote Originally Posted by Cambalinho View Post
    i have tested and the problem is other
    What did you test and how?

    Quote Originally Posted by Cambalinho View Post
    by some reason the compiler don't call that functions correctly
    It is not a compiler but you yourself "don't call that functions correctly"!
    First have a look at the documentation: http://www.cplusplus.com/reference/string/to_string/
    Then compare the type you pass in to_string with the available types: what the type is A of?
    Is it one of the mentiond in to_string documentation?
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2009
    Posts
    605

    Re: errors about types

    Quote Originally Posted by VictorN View Post
    i ahve seen the problem is other
    by some reason the compiler don't call that functions correctly

    see these code:
    Code:
     if (typeid(argHead)==typeid(char*))
                {
                    TextBlink(argHead, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                    Position.X=csbi.dwCursorPosition.X+strlen(argHead);
                }
                else if (typeid(argHead)==typeid(string))
                {
                    TextBlink(argHead.c_str(), csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                    Position.X=csbi.dwCursorPosition.X+argHead.length();
                }
    why the second 'if' is give me errors? don't make sence
    "C:\Users\Joaquim\Documents\CodeBlocks\My Class\console.h|178|error: request for member 'c_str' in 'argHead', which is of non-class type 'char*'|"
    "C:\Users\Joaquim\Documents\CodeBlocks\My Class\console.h|179|error: request for member 'length' in 'argHead', which is of non-class type 'char*'|"

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,273

    Re: errors about types

    Quote Originally Posted by Cambalinho View Post
    why the second 'if' is give me errors? don't make sence
    "C:\Users\Joaquim\Documents\CodeBlocks\My Class\console.h|178|error: request for member 'c_str' in 'argHead', which is of non-class type 'char*'|"
    "C:\Users\Joaquim\Documents\CodeBlocks\My Class\console.h|179|error: request for member 'length' in 'argHead', which is of non-class type 'char*'|"
    Compiler has no idea what type your argHead is of.
    If you are sure it is of the string type then try to cast it to string.
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2009
    Posts
    605

    Re: errors about types

    i found my error.. i was seen the read() better and my problem was here:
    Code:
    template <typename ...B>
        void write(string argHead, B... argTail)
    (like you see, i delete the 'typename A')
    heres the entire code:
    Code:
     void write()
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            cout <<"";
    
        }
    
    
        template <typename ...B>
        void write(string argHead, B... argTail)
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            if (blnBlink==true)
            {
                CONSOLE_SCREEN_BUFFER_INFO csbi;
    
                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
                string a;
                a=argHead;
                TextBlink(a, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                COORD Position;
                Position.X=csbi.dwCursorPosition.X+strlen(a.c_str());
                Position.Y=csbi.dwCursorPosition.Y;
                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Position);
            }
    
            else
                cout << argHead;
            write(argTail...);
        }
    
    
        template <typename ...B>
        void write(char *argHead, B... argTail)
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            if (blnBlink==true)
            {
                CONSOLE_SCREEN_BUFFER_INFO csbi;
    
                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
                string a;
                a=argHead;
                TextBlink(a, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                COORD Position;
                Position.X=csbi.dwCursorPosition.X+strlen(a.c_str());
                Position.Y=csbi.dwCursorPosition.Y;
                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Position);
            }
    
            else
                cout << argHead;
            write(argTail...);
        }
    
        template <typename A, typename ...B>
        void write(A argHead, B... argTail)
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            if (blnBlink==true)
            {
                CONSOLE_SCREEN_BUFFER_INFO csbi;
    
                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
                string a;
                //the error is in next 2 lines
                a=to_string(argHead);
                TextBlink(a, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                COORD Position;
                Position.X=csbi.dwCursorPosition.X+strlen(a.c_str());
                Position.Y=csbi.dwCursorPosition.Y;
                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Position);
            }
    
            else
                cout << argHead;
            write(argTail...);
        }
    only by the 'typename A' the compiler was confuse... but i fix it... thanks for all

  8. #8
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,263

    Re: [RESOLVED] errors about types

    Have a look at this

    Code:
    #include <string>
    #include <iostream>
    using namespace std;
    
    template<typename A>
    void typetest(A t)
    {
    	if (typeid(t)==typeid(char*)) {
    		cout << "got type char*" << endl;
    		cout << t << endl;
    	} else {
    		if (typeid(t)==typeid(string)) {
    			cout << "got type string" << endl;
    			cout << ((string)t).c_str() << endl;
    		}
    	}
    }
    
    
    int main()
    {
    string st = "This is a string";
    char carr[] = "This is a c array";
    
    	typetest<string>(st);
    	typetest<char*>(carr);
    	return 0;
    }
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  9. #9
    Join Date
    Apr 2009
    Posts
    605

    Re: [RESOLVED] errors about types

    Quote Originally Posted by 2kaud View Post
    Have a look at this

    Code:
    #include <string>
    #include <iostream>
    using namespace std;
    
    template<typename A>
    void typetest(A t)
    {
    	if (typeid(t)==typeid(char*)) {
    		cout << "got type char*" << endl;
    		cout << t << endl;
    	} else {
    		if (typeid(t)==typeid(string)) {
    			cout << "got type string" << endl;
    			cout << ((string)t).c_str() << endl;
    		}
    	}
    }
    
    
    int main()
    {
    string st = "This is a string";
    char carr[] = "This is a c array";
    
    	typetest<string>(st);
    	typetest<char*>(carr);
    	return 0;
    }
    please see my last post

  10. #10
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,263

    Re: [RESOLVED] errors about types

    Quote Originally Posted by Cambalinho View Post
    please see my last post
    Yeah - You posted between me reading and replying!
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  11. #11
    Join Date
    Apr 2009
    Posts
    605

    Re: [RESOLVED] errors about types

    Quote Originally Posted by 2kaud View Post
    Yeah - You posted between me reading and replying!
    thanks for all... you help me so much

  12. #12
    Join Date
    Apr 2009
    Posts
    605

    Re: [RESOLVED] errors about types

    VictorN thanks for all... thanks

  13. #13
    Join Date
    Apr 2009
    Posts
    605

    Re: [RESOLVED] errors about types

    Code:
    #include "console.h"
    
    int main()
    {
        char Text[]="hello world fdsfdsaffdsafjkdsnaljkfdsbaohjfbodhsjalbfndsljabnlfjdspaifjdsnkaklfndsçka";
        string c ="oi";
        int a=10;
        double b=20.34;
        Console.SetColorAndBackground(FOREGROUND_BLUE,BackColorCyan,true);
        Console.Clear();
        Console.read(Text);
        Console.write(Text,a,b,c);
        Console.read();
    }
    see these test??.. by some reason i have a memory leak. why? because windows tell me that the program stop to answer and then close it.
    can you advice me?
    (on write, if i use just the Text or if i take of the ',true' in SetColorAndBackground(), i don't get problems)
    Last edited by Cambalinho; November 6th, 2013 at 02:12 PM.

  14. #14
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,263

    Re: [RESOLVED] errors about types

    Without having the code for the Console class it's not possible to say.

    Use the debugger and trace through your code and see where is the problem.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  15. #15
    Join Date
    Apr 2009
    Posts
    605

    Re: [RESOLVED] errors about types

    Quote Originally Posted by 2kaud View Post
    Without having the code for the Console class it's not possible to say.

    Use the debugger and trace through your code and see where is the problem.
    strange if i execute normaly, i get the windows error, if i debug it theres no windows error... nothing

    Blink.h
    Code:
    #include <windows.h>
    #include <process.h>
    
    #include <string>
    #include <iostream>
    
    using namespace std;
    
    //ForeColor
    const int ForeColorBlack        = 0;
    const int ForeColorBlue         = FOREGROUND_BLUE;
    const int ForeColorGreen        = FOREGROUND_GREEN;
    const int ForeColorCyan         = FOREGROUND_BLUE | FOREGROUND_GREEN;
    const int ForeColorRed          = FOREGROUND_RED;
    const int ForeColorMagenta      = FOREGROUND_BLUE | FOREGROUND_RED;
    const int ForeColorBrown        = FOREGROUND_GREEN | FOREGROUND_RED;
    const int ForeColorLightGray    = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
    const int ForeColorDarkGray     = FOREGROUND_INTENSITY;
    const int ForeColorLightBlue    = FOREGROUND_BLUE | FOREGROUND_INTENSITY;
    const int ForeColorLightGreen   = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
    const int ForeColorLightCyan    = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
    const int ForeColorLightRed     = FOREGROUND_RED |  FOREGROUND_INTENSITY;
    const int ForeColorLightMagenta = FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY;
    const int ForeColorYellow       = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY;
    const int ForeColorWhite        = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY;
    
    //BackColor
    const int BackColorBlack        = 0;
    const int BackColorBlue         = BACKGROUND_BLUE;
    const int BackColorGreen        = BACKGROUND_GREEN;
    const int BackColorCyan         = BACKGROUND_BLUE | BACKGROUND_GREEN;
    const int BackColorRed          = BACKGROUND_RED;
    const int BackColorMagenta      = BACKGROUND_BLUE | BACKGROUND_RED;
    const int BackColorBrown        = BACKGROUND_GREEN | BACKGROUND_RED;
    const int BackColorLightGray    = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
    const int BackColorDarkGray     = BACKGROUND_INTENSITY;
    const int BackColorLightBlue    = BACKGROUND_BLUE | BACKGROUND_INTENSITY;
    const int BackColorLightGreen   = BACKGROUND_GREEN | BACKGROUND_INTENSITY;
    const int BackColorLightCyan    = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;
    const int BackColorLightRed     = BACKGROUND_RED |  BACKGROUND_INTENSITY;
    const int BackColorLightMagenta = BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY;
    const int BackColorYellow       = BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY;
    const int BackColorWhite        = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY;
    
    
    struct Blink
    {
        string Text;
        SHORT x;
        SHORT y;
        WORD  Attributes;
    };
    
    unsigned __stdcall BlinkLoop(void *params)
    {
        Blink *p = static_cast<Blink *>(params);
        SHORT tlen = static_cast<SHORT>(p->Text.length());
        SHORT x=p->x, y=p->y;
        HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
        const char *text=(char*)p->Text.c_str();
        CHAR_INFO *ConsoleText= new CHAR_INFO[tlen];
        CHAR_INFO *EmptyConsoleText= new CHAR_INFO[tlen];
        COORD a={tlen,1}, b={0,0};
        SMALL_RECT c={x, y,SHORT(x+tlen),SHORT(y+1)};
        int i=0;
        for (i=0; i<=tlen;i++)
        {
            ConsoleText[i].Char.AsciiChar  =text[i];
            ConsoleText[i].Attributes=p->Attributes;
            EmptyConsoleText[i].Char.AsciiChar  =' ';
            EmptyConsoleText[i].Attributes=p->Attributes;
        }
    
        while (true)
        {
            WriteConsoleOutput(hout,ConsoleText,a,b,&c);
            Sleep(500);
            WriteConsoleOutput(hout,EmptyConsoleText,a,b,&c);
            Sleep(500);
        }
        return 0;
    }
    
    void TextBlink(const string Text, SHORT  x, SHORT  y, const WORD TextAttribute=ForeColorWhite | ForeColorBlack)
    {
        Blink *b = new Blink;
        b->Text = Text;
        b->Attributes=TextAttribute;
        b->x=x;
        b->y =y;
    
        _beginthreadex(NULL, 0, BlinkLoop, b, 0, NULL);
    }
    Console.h
    Code:
    /*heres a nice class for work with console commands, properties and events*/
    
    /*#ifndef myheadguard1
    #define myheadguard1
    //insert contents of header here
    #endif*/
    
    #include <iostream>
    #include <typeinfo>
    #include <string>
    #include <Windows.h>
    #include <conio.h>
    #include <sstream>
    #include <cstddef>
    #include <typeinfo>
    #include <stdio.h>
    #include <clocale>
    #include "TextBlink.h"
    
    #define MY_BUFSIZE 1024
    
    const std::string NewLine = "\n";
    
    using namespace std;
    
    struct Position
    {
    	int X;
    	int Y;
    };
    
    struct Size
    {
    	int Width;
    	int Height;
    };
    
    class Console
    {
    	private:
    	char pszOldWindowTitle[MY_BUFSIZE];
    	HWND ConsoleHandle;
    	HDC ConsoleDC;
    	bool blnVisible;
        bool ReadEnter=false; //these boolean variable is for distinguish the functions used;)
    
    
    
        //properties
    	DWORD GetConsoleSize(HANDLE sout, COORD& size)
    	{
    		CONSOLE_FONT_INFO	cfinfo;
    
    		COORD		fsize;
    
    		WINDOWINFO	winfo;
    
    		if (!GetCurrentConsoleFont(sout, FALSE, &cfinfo))
    		{
    			return (GetLastError());
    		}
    
    		fsize = GetConsoleFontSize(sout, cfinfo.nFont);
    		if (!fsize.X && !fsize.Y)
    		{
    			return (GetLastError());
    		}
    
    		winfo.cbSize = sizeof(WINDOWINFO);
    		if (!GetWindowInfo(GetConsoleWindow(), &winfo))
    		{
    			return (GetLastError());
    		}
    
    		size.Y = (SHORT)((winfo.rcClient.bottom - winfo.rcClient.top) / fsize.Y);
    		size.X = (SHORT)((winfo.rcClient.right - winfo.rcClient.left) / fsize.X);
    
    		return (0);
    	}
    
    	bool blCaretVisible;
        bool blnBlink=false;
    
    
    public:
        void (*print)(){};
    	//initializate
    
        Console ()
    	{
    		COORD    consize;
    		HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
    		GetConsoleSize(hcon, consize);
    		SetConsoleScreenBufferSize(hcon, consize);
            SetVisible(true);
        }
    
        Console (void (*create) ())
    	{
    		COORD    consize;
    		HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
    		GetConsoleSize(hcon, consize);
    		SetConsoleScreenBufferSize(hcon, consize);
            SetVisible(true);
            create();
        }
    
    	//HDC and Handle and Hwnd
    	HDC hdc()
    	{
    		return GetDC(GetConsoleWindow());
    	}
    
    	HWND hwnd()
    	{
    		return GetConsoleWindow();
    	}
    
    	HANDLE handle()
    	{
    		return GetStdHandle(STD_OUTPUT_HANDLE);
    	}
    
    	//Console title
    	string ConsoleTitle()
    	{
    		GetConsoleTitle( pszOldWindowTitle,MY_BUFSIZE);
    		return string(pszOldWindowTitle);
    	}
    
    	void ConsoleTitle(string title)
    	{
    		SetConsoleTitle(title.c_str());
    	}
    
    
    	//Console Position
    	POINT GetConsolePosition()
    	{
    		POINT a;
    		RECT WindowRect;
    		GetWindowRect(GetConsoleWindow() ,&WindowRect);
    		a.x=WindowRect.left;
    		a.y=WindowRect.top;
    		return a;
    	}
    
    	void SetConsolePosition(POINT Position )
    	{
    		SetWindowPos(GetConsoleWindow(),HWND_TOP,Position.x,Position.y,0,0,SWP_SHOWWINDOW||SWP_NOOWNERZORDER);
    	}
    
        void write()
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            cout <<"";
    
        }
    
    
        template <typename ...B>
        void write(string argHead, B... argTail)
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            if (blnBlink==true)
            {
                CONSOLE_SCREEN_BUFFER_INFO csbi;
    
                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
    
                TextBlink(argHead, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                COORD Position;
                Position.X=csbi.dwCursorPosition.X+strlen(argHead.c_str());
                Position.Y=csbi.dwCursorPosition.Y;
                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Position);
            }
    
            else
                cout << argHead;
            write(argTail...);
        }
    
    
        template <typename ...B>
        void write(char *argHead, B... argTail)
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            if (blnBlink==true)
            {
                CONSOLE_SCREEN_BUFFER_INFO csbi;
    
                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
                string a;
                a=argHead;
                TextBlink(a, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                COORD Position;
                Position.X=csbi.dwCursorPosition.X+strlen(a.c_str());
                Position.Y=csbi.dwCursorPosition.Y;
                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Position);
            }
    
            else
                cout << argHead;
            write(argTail...);
        }
    
        template <typename A, typename ...B>
        void write(A argHead, B... argTail)
        {
            setlocale(LC_ALL, "en_US.UTF-8");
            if (blnBlink==true)
            {
                CONSOLE_SCREEN_BUFFER_INFO csbi;
    
                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
                string a;
                a=to_string(argHead);
                TextBlink(a, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,csbi.wAttributes);
                COORD Position;
                Position.X=csbi.dwCursorPosition.X+strlen(a.c_str());
                Position.Y=csbi.dwCursorPosition.Y;
                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Position);
            }
    
            else
                cout << argHead;
            write(argTail...);
        }
    
        //Read
    	//empty
    
    	void read()
    	{
    	    if (ReadEnter==false)
            {
                while(kbhit())
                        ;
                HANDLE hConIn = CreateFileW(L"CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
    
                DWORD oldMode;
                GetConsoleMode(hConIn, &oldMode);
                SetConsoleMode(hConIn, ENABLE_LINE_INPUT);
    
                FlushConsoleInputBuffer(hConIn);
    
                char buffer[1];
                DWORD read;
                ReadConsoleA(hConIn, buffer, sizeof(buffer), &read, nullptr);
    
                SetConsoleMode(hConIn, oldMode);
                CloseHandle(hConIn);
            }
    	}
    
        template<typename ...B>
        void read(string &s, B&... tail)
        {
            ReadEnter=true;
            while(kbhit())
                ;
            setlocale(LC_ALL, "en_US.UTF-8");
            getline(cin, s);
            read(tail...);
            ReadEnter=false;
        }
    
        template<typename ...B>
        void read(char s[256], B&... tail)
        {
            ReadEnter=true;
            while(kbhit())
                ;
            setlocale(LC_ALL, "en_US.UTF-8");
            cin.getline(s,256);
            read(tail...);
            ReadEnter=false;
        }
    
        template <typename A, typename ...B>
        void read(A &argHead, B&... argTail)
        {
            ReadEnter=true;
            while(kbhit())
            setlocale(LC_ALL, "en_US.UTF-8");
            cin >> argHead;
            read(argTail...);
            ReadEnter=false;
        }
    
    	//clear the Console
    	void Clear(int BackColor=-1)
    	{
    		 // home for the cursor
    		COORD coordScreen = {0, 0};
    		DWORD cCharsWritten;
    		CONSOLE_SCREEN_BUFFER_INFO csbi;
    		DWORD dwConSize;
    
    		// Get the number of character cells in the current buffer
    		if(!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
                return;
    		dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    
    		// Fill the entire screen with blanks
    		if(!FillConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE), (WCHAR)' ', dwConSize, coordScreen, &cCharsWritten))
                return;
    
    		// Get the current text attribute.
    		if(!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
                return;
            if (BackColor!=-1)
            {
                DWORD textcolor = csbi.wAttributes & 0xff0f;
                //DWORD backcolor = (csbi.wAttributes & 0xfff0) >> 4;
                csbi.wAttributes=textcolor | BackColor ;//here we change the backcolor
            }
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), csbi.wAttributes );
    		// Set the buffer's attributes accordingly.
    		if(!FillConsoleOutputAttribute(GetStdHandle(STD_OUTPUT_HANDLE), csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten))
                return;
    		// Put the cursor at its home coordinates.
    		SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coordScreen);
    	}
    
    	//Turn cursor on
    	DWORD CursorOn(HANDLE sout)
    	{
    		CONSOLE_CURSOR_INFO	cur;
    
    		if (!GetConsoleCursorInfo(sout, &cur))
    		{
    			return (GetLastError());
    		}
    
    		cur.bVisible = TRUE;
    		return (!SetConsoleCursorInfo(sout, &cur) ? GetLastError() : 0);
    	}
    
    
    	//Turn cursor off
    	DWORD CursorOff(HANDLE sout)
    	{
    		CONSOLE_CURSOR_INFO	cur;
    
    		if (!GetConsoleCursorInfo(sout, &cur))
    		{
    			return (GetLastError());
    		}
    
    		cur.bVisible = FALSE;
    		return (!SetConsoleCursorInfo(sout, &cur) ? GetLastError() : 0);
    	}
    	bool GetCaretVisible()
    	{
    		return blCaretVisible;
    	}
    
    	void SetCaretVisible(bool Visible)
    	{
    		if (Visible==true)
    		{
    			CursorOn(handle());
    		}
    		else
    		{
    			CursorOff(handle());
    		}
    		blCaretVisible=Visible;
    	}
    
    
    	void SetColorAndBackground(int ForgC, int BackC=0, bool Blink=false)
    	{
    	    blnBlink=Blink;
    		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), ForgC | BackC );
    	}
    
    	void SetConsoleIcon(char *strIconPath)
    	{
    		HANDLE lIcon;
    		lIcon = LoadImage(0,strIconPath , 1, 0, 0, LR_LOADFROMFILE);
    		SendMessage(GetConsoleWindow()  , WM_SETICON, 0,(LPARAM) lIcon) ;
    	}
    
    	COORD GetCaretPosition()
    	{
    		COORD s;
    		CONSOLE_SCREEN_BUFFER_INFO csbi;
    
    		GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
    		s.X=csbi.dwCursorPosition.X;
    		s.Y=csbi.dwCursorPosition.Y;
    		return s;
    	}
    
    	void SetCaretPosition(COORD Position)
    	{
    		SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Position);
    	}
    
    	bool GetVisible()
    	{
    		return blnVisible;
    	}
    
    	void SetVisible(bool visible)
    	{
    		if (visible== true)
    		{
    			ShowWindow(GetConsoleWindow(),SW_SHOWNORMAL);
    		}
    		else
    		{
    			ShowWindow(GetConsoleWindow(),SW_HIDE);
    		}
    		blnVisible=visible;
    	}
    
    
    	COORD GetConsoleWindowSize()
    	{
    		COORD    consize;
    		HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
    		GetConsoleSize(hcon, consize);
    		//SetConsoleScreenBufferSize(hcon, consize);
    		return consize;
    	}
    
    	void SetConsoleWindowSize(COORD Size)
    	{
    		SMALL_RECT s;
    		POINT WindowPos;
    		CONSOLE_SCREEN_BUFFER_INFO csbi;
    		HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
    		WindowPos=GetConsolePosition() ;
    		s.Left=(SHORT)WindowPos.x;
    		s.Top=(SHORT)WindowPos.y;
    		s.Bottom=(SHORT)WindowPos.y+Size.Y;
    		s.Right= (SHORT)WindowPos.x+Size.X;
    
    		GetConsoleScreenBufferInfo( hcon, &csbi);
    		if  (Size.X > (csbi.srWindow.Bottom- csbi.srWindow.Top) || Size.Y >   (csbi.srWindow.Right- csbi.srWindow.Left))
    		{
    			SetConsoleScreenBufferSize(hcon, Size);
    		}
    		SetConsoleWindowInfo(hcon,true,&s);
    	}
    
    }Console;
    the main.cpp
    Code:
    #include "console.h"
    
    int main()
    {
        char Text[]="hello world fdsfdsaffdsafjkdsnaljkfdsbaohjfbodhsjalbfndsljabnlfjdspaifj";
        string c ="oi";
        int a=10;
        double b=20.34;
        Console.SetColorAndBackground(FOREGROUND_BLUE,BackColorCyan,true);
        Console.Clear();
        Console.read(Text);
        Console.write(a,b,Text,c);
        Console.read();
    }

Page 1 of 2 12 LastLast

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center