Error using std::cout in visual cpp console application - c++

I am using visual studio 2013 to build a C++ console application.This is my code which gives an error. I need to write to the console for every function in my application.
// RAT.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Process started";
return 0;
}
It gives the following error,
Error:namespace "std" has no member "cout"
I dont understand why this basic "cout" gives a such error :(
Please help me I am totally confused....

You need to place #include <iostream> as your header.

Related

Visual Studio 2017 "Unable to start program. The system cannot find the file specified"

I'm following this tutorial to create a C++ Hello World app for Visual Studio.
https://tutorials.visualstudio.com/cpp-console/install
I've installed the software, selected "Windows Console Application" and copy/pasted the Hello World program from the tutorial:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!\n";
return 0;
}
However, when I try to run the Local Windows Debugger, I get this error:
Unable to open program.
\repos\HelloWorld\Debug\HelloWorld.exe
The system cannot find the file specified.
How would I include an .exe file?
Also, I have an error "cannot open stdafx.h", but I assume that's connected to this.
EDIT:
I removed "#include "stdafx.h"" and got the same error. It also said there was an unexpected end of file and suggested I #include "pch.h", so I did.
#include <iostream>
#include "pch.h"
using namespace std;
int main()
{
cout << "Hello, world!\n";
return 0;
}
I'm still getting the error that it can't find .exe ...also 'cout' is an undeclared identifier.

Can't enter c++ code on Visual Studio 2017

I am creating a Windows console application using visual studio 2017, but the console only accepts c code. I am trying to enter:
#include <iostream>
int main()
{
std::cout << "Hello World";
}
It gives some errors like saying "cout" doesn't exist, "std" doesn't contain "cout" and many others. However if I change the code to:
#include "stdafx.h"
int main()
{
printf("Hello World");
}
It works fine. How do I make it accept c++ code?

What's wrong with std::strings

Hi I am new to C++ and Code::Block
I am trying to make a simple code to test it, using strings.
when I compile the code there is no problem, but when I try to debug it, Code::Block gives me the following warning:
Cannot open file:
File:../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c
Info: "Multiple information windows with the same message have been
supressed."
Image of the error FYI:
Part of the code that gives me an error.
inside main function
#include <iostream>
#include <string>
int main ()
{
std::mystring("What's wrong with strings");
return 0;
}
I realise that this error only occurs when I try to debug a string or a file containing a string.
Any help would be appreciated.
some other information that might help:
Code::Block 16.01
Compiler MinGW gcc4.9.2
Windows 7 Professional 32 bits SP1
First of all, to use strings you must include the file header string. And the name of the type string is..std::string, not std::mystring.
#include <string>
int main(int argc, char** argv)
{
std::string mystring("Nothing's wrong with strings");
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
string mystring = "Whats wrong with my string";
return 0;
}
If you write it in the following way, it should work.
It's safer to define strings like I showed it. It will be also easier for you if you add using namespace std in the beginning of every program if you are new to C++.

c++ std error in code

I just started c++
here is the code for a basic main declaration and based on many tutorails I have found, also contains the code to print hello world to console
// TestApp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Hello World";
}
I am using VS 2012 Express, I dont know which compiler but the "cout" is underlined in red
errors are as follows:
error C2039 'cout': is nit a member of 'std' ln 9 col 1 error
C2065 : undeclared identifier ln 9 col 1 IntelliSense:
namespace "std" has no member "cout" ln 9 col 7
I do not understand why it is giving an error, could someone please enlighten me?
The error is telling you that std::cout hasn't yet been declared anywhere in this translation unit. You can't use something if it hasn't been declared. std::cout is declared in the C++ standard library <iostream> header:
#include <iostream>
If you receive a similar error in the future and you need to know which header to include, look up some documentation for the particular function/type you want to use. For example, if you look at cppreference.com, it states "Defined in header <iostream>".
Include below code :
#include <iostream>
Try this:
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Hello World";
}
should be fine now

What kind of VS 2010 C++ Project I must choose to compile a simple Borland C++ 5 Console app?

I have a simple Win32 console (no vcl) app written in Borland C++ 5, now I want compile the same application in VS 2010. but I'm new using this IDE and I don't know how run the code in VS. I tried choosing Win32 Console Application. but even i very simple app like this
#include <iostream.h>
#pragma hdrstop
#pragma argsused
int main(int argc, char* argv[])
{
cout << "Hello" << endl;
getchar();
return 0;
}
does not compile in VS.
So, What kind of VS 2010 C++ Project I must choose to compile a simple Borland C++ 5 Console app? or I need modify my app in order to use VS C++?
<iostream.h> is deprecated, and VS10 does not support it, use <iostream> instead, and you'll also need std::cout, std::endl , etc.. i.e.
#include <iostream>
#pragma hdrstop
// #pragma argsused // I don't believe this is valid in VS10
int main(int argc, char* argv[])
{
std::cout << "Hello" << std::endl;
std::cin.get();
return 0;
}
Alternatively, if you don't want to prefix your library uses with std::, you can put a using declaration at the top, after the headers:
using namespace std;