Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2012
    Location
    Hamburg, Germany
    Posts
    93

    cin is ambiguous

    Hey Folks!
    Yesterday i attempted to the public c++101 class, it was the first time i got in touch with c++.
    To get comfortable with all the new stuff i tried to build the first c#101 Homework (Vending-Machine) with c++.
    So far so good, the application does compile correctly.



    But then i tried to write an TryParse-Check to verify that the user puts numbers in the console and no letters.
    It failed, so i removed the code. After removing it and setting the code to the old (working) state, i got this error-message:
    "Intellisense: "cin" is ambiguous".


    The Application still compiles normally, but in the IDE i got since then for every "cin" in code an error (it is shown as an error and not a warning in the IDE-error-list).
    After closing Visual Studio Express and starting it again, the errors dissapeared. After trying again to write the TryParse-statement and removing it again, the errors occured again. But compiling is still no problem.
    What is this? Have anyone expierienced that behaviour in the IDE?
    a bit saved is a bit earned

  2. #2
    Join Date
    Mar 2009
    Location
    Bellevue, WA
    Posts
    803
    Could you post your code? So I can see the other areas that you're using cin.

    Also, if nothing appears wrong with your code you may also want to try a clean and rebuild. I'm not sure off the top of my head but the shortcut may be F7
    Last edited by Kwest; 04-10-2012 at 03:19 PM.
    " Imagination is the preview of life's coming attractions " - Albert Einstein
    " If you can't explain it simply, you don't understand it well enough." - Albert Einstein

    My Website: http://www.gamedevlounge.com/

    If any post is informative please provide positive feedback by clicking the star below.

  3. #3
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    Those intellisense errors are very hard to track. Fortunately, they don't have any effect on the compilation, just on the auto-completion inside the editor.

    Usually, it helps deleting all intellisense related files (the .sdf file and the ipch folder) from the source folder, but sometimes only sacrificing a goat on a full moon will make those errors disappear.

    On an unrelated note: I noticed you are using the German version of VS, which is not very good. If your language skills allow it, consider switching to the English version. I'm a native German speaker with English as a second language, and still most of the time I have a much harder time understanding the German version than the English one, because the translation is so bad...

  4. #4
    Join Date
    Jan 2012
    Location
    Hamburg, Germany
    Posts
    93
    i made a video that makes it very easy to follow what exactly happens in VS.
    http://www.youtube.com/watch?v=HOGYiaJn2yg
    And here is the code:
    Code:
     
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    
    
    int main()
    {
    	int choice = 0;
    	int amountOfMoney = 0;
    	cout << "welcome to the vending machine! enter the amount of money you have to spend:\n";
    
    	cin >> amountOfMoney;
    
    	cout << "money to spend:\n" << amountOfMoney << endl;
    
    	cout << "please select an item:\n";
    	cout << "[1] Coke   $3  \n";
    	cout << "[2] Pepsi  $52 \n";
    	cout <<	"[3] Mt Dew $20 \n";
    	cout <<	"[4] Hunter $10 \n";
    	
    	cin >> choice; 
    	
    	switch(choice)
    	{
    	case 1:
    		if(amountOfMoney >= 3)
    		cout << "you have left " << amountOfMoney - 3 << " $";
    		else
    		cout << "you don't have enough money left." << endl;
    		break;
    	case 2:
    		if(amountOfMoney >= 52)
    		cout << "you have left " << amountOfMoney -52 << " $";
    		else
    		cout << "you don't have enough money left." << endl;
    		break;
    
    	case 3:
    		if(amountOfMoney >= 20)
    		cout << "you have left " << amountOfMoney -20 << " $";
    		else
    		cout << "you don't have enough money left." << endl;
    		break;
    	case 4:
    		if(amountOfMoney >= 10)
    		cout << "you have left " << amountOfMoney - 10 << " $";
    		else
    		cout << "you don't have enough money left. " << endl;
    		break;
    	default:
    		cout << "false input";
    		break; 
    	}
    	
    	
    	cin.ignore(); 
    	
    	cin.get(); 
    
    
    	return 0;
    
    }
    the reason i use the german version of VS is simply that it was the first search result in google when i searched for VS Express c++ Edition, but changing to english version is not a bad idea.

    Pressing F7 did not help. Sacrifice a goat on the full moon for glory and Visual Studio sounds to me almost better than deleting the .sdf-file, because it annoys me that i don't have any clue about why VS is grumbling on this one. If it starts to make noise on this tiny application, i don't want to know how much pain in the ass it will cause on bigger projects (that hopefully will follow).
    a bit saved is a bit earned

  5. #5
    Join Date
    Mar 2009
    Location
    Bellevue, WA
    Posts
    803
    I opened up my spike solution and copy pasted your code and built it and it built perfectly fine with no warnings or errors (no complaints about cin being ambiguous) I also didn't see anything in your code that would cause this error/warning. It may very well have something to do with German Version of VS as comicSans stated.
    " Imagination is the preview of life's coming attractions " - Albert Einstein
    " If you can't explain it simply, you don't understand it well enough." - Albert Einstein

    My Website: http://www.gamedevlounge.com/

    If any post is informative please provide positive feedback by clicking the star below.

  6. #6
    Join Date
    Jan 2012
    Location
    Hamburg, Germany
    Posts
    93
    @Kwest: on line-number 24 you have this statement:
    cin >> choice;
    replace this statement with "if (cin..." thats enough to provocate the errorlist to tell that the cin is ambiguous. When you now remove this "if(cin..)" and replace it with the former "cin>> choice;" again, the error-state "cin is ambiguous" still remaines.
    If i open VS and compile the application, the error-list doesnt mocker, but it starts with it when i type "if (cin " and delete this again. You can monitor this behaviour very well in the video i made.
    Now i re-installed VS in the englisch version. The error still occures. I also saw that you can switch in the settings between the languages (Tools -> Options -> Environment -> International settings), so the re-installation was needless, its the same program only with other fonts.
    a bit saved is a bit earned

  7. #7
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    Quote Originally Posted by Kwest View Post
    It may very well have something to do with German Version of VS as comicSans stated.
    I never said that.

    Quote Originally Posted by Grundkurs View Post
    If i open VS and compile the application, the error-list doesnt mocker, but it starts with it when i type "if (cin " and delete this again. You can monitor this behaviour very well in the video i made.
    I was able to reproduce this behavior. Seems to be a bug in VS. The error messages disappear though after you mess around with the code some more.

    Here are your options:
    Don't display Intellisense errors: Right-click in the Error List Window and deselect 'Show Intellisense Errors'. As I've said before, they don't have any influence on the compilation, so there is no harm in not showing them.

    Alternatively, don't use using namespace std. Seems VS only punishes people who are too lazy to make proper use of namespaces . In particular, the error goes away if you use fully qualified names (i.e. std::cin and no using declarations at all) or if you use precise using declarations (i.e. using std::cin; etc. instead of using namespace std;). Since using namespace std; is not the best style in the first place, this might be the way to go.

  8. #8
    Join Date
    Jan 2012
    Location
    Hamburg, Germany
    Posts
    93
    yeah it also feels like a kind of a bug and its good to hear from another one that it really seems to be one. Using std:: instead of the namespace declaration above the int main() method is no big deal for me. With using of std::cin the problem dissapears. Thanks a lot for the help!
    a bit saved is a bit earned

  9. #9
    Join Date
    Mar 2009
    Location
    Bellevue, WA
    Posts
    803
    Quote Originally Posted by ComicSansMS View Post
    On an unrelated note: I noticed you are using the German version of VS, which is not very good.
    Hey ComicSansMS sorry I misunderstood the line above. I just assumed there was something wrong with the German version causing this bug based on you saying it wasn't very good. I now know you meant because of the translation between the two versions. That's what I get when making an assumption

    I would have suggested getting rid of the "using directive" and only using "using declarations" but I wasn't able to reproduce the error in VS. I consider that odd behavior.

    To clarify though for others the difference between a using directive and using declaration, a using directive is when you say
    Code:
    using namespace std;
    this makes the everything in the standard namespace available to you, whereas a using declaration is basically saying hey I only need to use this one specific thing from the standard namespace so don't make the whole namespace available just what I declare like so
    Code:
    using std::cin;
    using std::cout;
    using std::endl;
    //etc...
    using directives are considered lazy by some programmers but I think it's okay when starting out and you're learning. You can be more specific once you start feeling comfortable with what's available.

    Grundkurs I'm glad you figured it out. Sorry, I couldn't be of more help maybe next time.
    " Imagination is the preview of life's coming attractions " - Albert Einstein
    " If you can't explain it simply, you don't understand it well enough." - Albert Einstein

    My Website: http://www.gamedevlounge.com/

    If any post is informative please provide positive feedback by clicking the star below.

Posting Permissions

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