Really new at this. I tried to write a program just to pass a variable into a class and cout it from main. When I finished the cout command wasn't rebonised. I had included iostream....I captioned out all the rest of the program....I copied and pasted the cout command from my "hello world" program. It still wouldn't work. At first it said cout not identifier and then said it wasn't part of Std (I'm paraphrasing)....I started a new project....wrote the same code and it worked perfectly. Any ideas what happened? I'm using virtual studio 2017
Are you doing everything in one file or do you have multiple files? If you have multiple files, make sure they have #include <iostream> in them, as well. If you are including "stdafx.h", include iostream after it.
Other than that, we can only guess: post the code.
Heres the code guys....you can see where I've captioned out the rest of the program...and it is a .cpp file and yes this is just one file.
#include "stdafx.h"
#include <string>
/*
using namespace std;
class myclass {
public:
void setval(int a, int b) {
valuetoset = a + b;
}
int getvalue() {
return valuetoset;
}
private:
int valuetoset;
};
*/
int main()
{
std::cout << "";
you should have to include<iostream> to get cout ... visual sometimes has include chains that would pull it in externally and it would work without but you should include it.
Sorry guys....I didn't paste and copy the #include <iostream> ...it is there....ah but it is above the stdafx.h ...that matters does it? Right...thanks for the help folks...May my learning continue.
stdafx is a visual studio / microsoft thing and it behaves oddly. It is best practice to make it the first thing, but that isnt tied to the c++ language directly, its just a nuance of that IDE and how it does things. Back when I used VS I actually immediately removed this line from all programs and turned off the settings that used it (precompiled headers and such) because they caused nonstop problems (this was a LONG time ago, prob VS 2008 or so).