![]() |
| | #1 |
| Registered User Join Date: Sep 2004
Posts: 3
| Simple simple program Code: #include <iostream>
#include <string>
#include "stdafx.h"
int main()
{
std::string name("This is a test!");
std::cout << name << std::endl;
return 0;
}
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) I am using Visual c++ .NET. Can someone please tell me why this doesn't work? thanks! |
| Ryback is offline | |
| | #2 |
| Arggggh Join Date: Sep 2004
Posts: 227
| hmmm.....not sure.....it works for me in dev-cpp
__________________ Keyboard Not Found! Press any key to continue. . . |
| DeepFyre is offline | |
| | #3 |
| Registered User Join Date: Apr 2003
Posts: 74
| Worked for me too...sorry...wish i could tell ya.
__________________ big146 |
| big146 is offline | |
| | #5 |
| Arggggh Join Date: Sep 2004
Posts: 227
| ya you dont get stafx.h with dev cpp
__________________ Keyboard Not Found! Press any key to continue. . . |
| DeepFyre is offline | |
| | #6 |
| Carnivore ('-'v) Join Date: May 2002
Posts: 2,865
| I would remove the stdafx.h, simply because in this case there is absolutely no use for it. Other than that however, I see nothing syntactically wrong with your code - unless of course the C++ standard does not allow use of std::string with cout's << operator, which I highly doubt since nearly every compiler allows it. If you want it to *work* though, try using name.c_str() instead of name. It is guaranteed to be supported by the standard. And if that doesn't work, then you know your compiler's screwed
__________________ Just Google It. √ (\ /) ( . .) c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination. |
| Hunter2 is offline | |
| | #7 |
| Registered User Join Date: Sep 2004
Posts: 3
| Thanks all for the help. I found some more information. When I create my project in Visual Studio I am choosing a "Win32 Console Project". This is why the #include "stdafx.h" line is there (and cannot be removed). But the program does not work. But here is what else I discovered: if I instead create a "Console Application (.NET)" project, the program will work without any errors. Does anyone have experience with Visual Studio who can help? Thanks guys. |
| Ryback is offline | |
| | #8 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| move the line #include "stdafx.h" To the top of your includes. stdafx.h must always be included first. |
| bithub is offline | |
| | #9 | |
| Registered User Join Date: Sep 2004
Posts: 3
| Quote:
Bithub, that works! Thank you!! | |
| Ryback is offline | |
| | #10 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| > This is why the #include "stdafx.h" line is there Remove it, and then turn off "precompiled headers" in the project settings.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #11 |
| Registered User Join Date: Apr 2003
Posts: 74
| If you want to run just a simple console app, select win32 >> then console project, when the application wizzard dialog pops up select application settings and then select Empty project. After the solution loads up right click source files and select add >> then new item >> from the list of templates select cpp. that will give you a project without the stdafx.h header files. then just add your code from the book.
__________________ big146 |
| big146 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using variables in system() | Afro | C Programming | 8 | 07-03-2007 12:27 PM |
| [Help] Simple Array/Pointer Program | sandwater | C Programming | 3 | 03-30-2007 02:42 PM |
| simple silly program | verbity | C Programming | 5 | 12-19-2006 06:06 PM |
| fopen(); | GanglyLamb | C Programming | 8 | 11-03-2002 12:39 PM |
| Need help with simple DAQ program | canada-paul | C++ Programming | 12 | 03-15-2002 08:52 AM |