Help, very simple C++ code wont work on MSVC.

Started by
11 comments, last by Ice-T 20 years, 8 months ago
Can somebody tell why this wont work? #include <iostream> int main() { char r = ''r''; cout << r; return(0); } It tells me that cout is unrecognized. Prior to this, it said that and couldn''t be found. If so, where can I get these files? It''s not on my MSVC CD.
Advertisement
try this:
cout < < r < < endl;

[edited by - Jekuto on August 9, 2003 12:47:37 AM]
Chinese boy with a bad English:P
You need to type

using namespace std;

after #include <iostream>

#include <iostream>int main() {  char r = 'r';  std::cout << r;  return(0); }


Bakingsoda36's method works, too.

[edited by - smart_idiot on August 9, 2003 12:53:46 AM]
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Thanks for the help but that''s not it. I keep getting this error:

c:\program files\microsoft visual studio\vc98\include\xlocale(11) : fatal error C1083: Cannot open include file: ''stdexcept'': No such file or directory
Error executing cl.exe.

Where can I get the "stdexcept"? I can''t seem to get it off my MSVC CD.
You might want to try putting .h after the file''s name. If namespaces don''t work....

ex.
#include <iostream>
using namespace std;

... this may work out better for you...

#include <iostream.h>
// using namespace std; <-- don''t need this with *.h

Also, if you are working with Visual Studio (esp. 6.0), make sure your project is a Win32 Console Application, not a Win32 Application.

I hope this works out for you.
~Belgarion
char r="r";

should also work.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
quote:Original post by RhoneRanger
char r="r";

should also work.

No it shouldn't. Don't be a dumbass; that's an implicit conversion from "const char*" to "char", which doesn't work in any context. How could that possibly help anything?

[edited by - zealouselixir on August 10, 2003 1:35:36 AM]

[twitter]warrenm[/twitter]

I believe that trying to use:

char r = "r";

as opposed to:

char r = ''r'';

will result in an error.

The "r" is a null terminating string, so there is a hidden element, the ''\0'' character. A char type will only accept a single char type, not two. If you turn r into:

char r[2];

Then you might be able to work around that. If I am mistaken, please tell me.

~Belgarion
quote:Original post by Anonymous Poster
You might want to try putting .h after the file''s name. If namespaces don''t work....

No, don''t do this.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]

This topic is closed to new replies.

Advertisement