[RESOLVED] what's wrong with 'cout' with strings?:(
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: [RESOLVED] what's wrong with 'cout' with strings?:(

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Posts
    625

    [RESOLVED] what's wrong with 'cout' with strings?:(

    see these class:
    Code:
    #include <iostream>
    #include <Windows.h>
    #define MY_BUFSIZE 1024
    using namespace std;
    
    
    
    
    class Console
    {
    char pszOldWindowTitle[MY_BUFSIZE];
    
    
    	public:
    string Title() //the problem seems to be here, but no erro message here
    	{		
    		GetWindowText(GetForegroundWindow(), pszOldWindowTitle, GetWindowTextLength(GetForegroundWindow()) + 1);
    		return string(pszOldWindowTitle);
    	}
    	
    	void Title(string title)  //these procedure works fine
    	{		
    		SetConsoleTitle(title.c_str());
    	}
    };
    (sorry the indention, but i can't use 'TAB' key)
    and heres how i use it:

    Code:
    #include "stdafx.h"
    #include "Console.h"
    #include <iostream>
    #include <conio.h>
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	Console a;
        string b =string(a.Title());
    
    
        cout << "Title: " << b << endl; //i get 1 problem in second '<<'
    
    
        Sleep(5000);
    
    
        a.Title("Hello World");
    
    
        getch();
    
    
        return 0;
    }



    error message:

    1 - "error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)";

    2 - " IntelliSense: no operator "<<" matches these operands".

    what is wrong with cout???? isn't the 1st time that i get these type of error, but i continue without understand why
    can anyone explain to me?

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

    Re: what's wrong with 'cout' with strings?:(

    Did you try to
    Code:
    #include <string>
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Posts
    625

    Re: what's wrong with 'cout' with strings?:(

    Quote Originally Posted by VictorN View Post
    Did you try to
    Code:
    #include <string>
    thank you. so every that i use the string, i must include that file.. thank you very much.
    i have more 2 questions for close the topic:

    1 - what means: title.c_str()?
    (title it's a string variable)

    2 - "warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch."
    why these warning? the '_getch' can be used in Dev C++ too?

  4. #4
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,308

    Re: what's wrong with 'cout' with strings?:(

    Quote Originally Posted by Cambalinho View Post
    thank you. so every that i use the string, i must include that file.. thank you very much.
    i have more 2 questions for close the topic:

    1 - what means: title.c_str()?
    (title it's a string variable)

    2 - "warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch."
    why these warning? the '_getch' can be used in Dev C++ too?
    1) See http://www.cplusplus.com/reference/string/string/c_str/

    2) See http://stackoverflow.com/questions/8...-is-deprecated
    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.

  5. #5
    Join Date
    Apr 2009
    Posts
    625

    Re: what's wrong with 'cout' with strings?:(

    thanks for all
    VictorN and 2kaud: do you recive the Rate?
    (if not... sorry, it's a forum problem\rules)

  6. #6
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,308

    Re: what's wrong with 'cout' with strings?:(

    Quote Originally Posted by Cambalinho View Post
    thanks for all
    VictorN and 2kaud: do you recive the Rate?
    (if not... sorry, it's a forum problem\rules)
    Unfortunately no, I haven't received your Rate.
    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.

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