C++ NetBEAN cout Error? - c++

#include <cstdlib>
using namespace std;
/*
*
*/
int main(int argc, char** argv)
{
cout << "COME AT ME BRO!\n"
return 0;
}
It says cout is unable to resolve identifier
The C++ code assistance is setup properly, I'm just not sure whatelse it could possibly be.

You did not include <iostream> and thus the identifier std::cout is never declared or defined in your program.

You're including the wrong header file. It should be :
#include <iostream>

Related

"time" is not a member of "std"

An error showed up saying "time" is not a member of "std" for the sentence:
std::srand(std::time(0));
<ctime> and <cstdlib> already included. And the compiler is TDM-GCC MinGW.
I met this error several times and I still can't figure out the reasons.
This is because time(2) is a C standard library function, not a C++ standard library function.
#include <iostream>
#include <ctime>
int main(int argc, char *argv[])
{
auto t = time(nullptr);
std::srand(t);
std::cout << t << "\n";
return 0;
}

Why YouCompleteMe still show syntax warning when I include the correct C++ library?

When I include the required library, the "#include.." line doesn't show any warning. But when I use the functions in that library, I find the Vim shows that "..use of undeclared function...". It seems that the library is not correctly included. So I want to know how to figure out this problem?
The screenshots for this question are attached as follows:
Try including it as follows:
#include <stdlib.h> //use <> instead of ""
Also, the "printf" function comes from the "cstdio" library so try implementing that library as well,
#include <stdio.h>
UPDATED
The easiest way to fix that problem is;
Include the stdio.h library
#include <stdio.h>
Then, instead of typing;
printf('s');
you do,
printf("s");
Now, if you really want to print a character 's', then use,
printf("%c", 's'); // Tells the printf function that 's' is a character
The final code would look like;
#include <stdio.h>
int main(int argc, char** argv) {
printf("s");
printf("%c", 's');
return 0;
}
Now, your comment was that "cout" does not work. In order for "cout" to work you need to include the iostream library:
#include <iostream>
Then, you can use "cout" in your code;
std::cout << 's';
std::cout << "s";
Or you can include "namespace std" and the "iostream" library to avoid using std:: before "cout"
include <iostream>
using namespace std;
Thereafter, use cout without std::
cout << 's';
cout << "s";
The final code would be;
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << 's';
cout << "s";
return 0;
}
If you want to learn more about what is in the iostream library and how to use it I recommend using this site:
http://www.cplusplus.com/reference/iostream/
Also, for the stdio.h,
http://www.cplusplus.com/reference/cstdio/

Good modularity in C++ using #define

As the title says I'm looking for a good way to do modularity in C++ using #define. Let me explain.
I have a simple settings header file like such:
//Settings.h
define HTTP
And a include file:
//include.h
#include <iostream>
using namespace std;
#ifdef HTTP
#include "HTTPStuff.cpp"
#endif
Main file:
//Main.cpp
#include "Include\Includes.h"
int main(int argc, char *argv[]) {
string res = HTTP_POST_REQUEST("localhost", "/script.php", "data=data1");
cout << res << endl;
cin.get();
}
The function HTTP_POST_REQUEST is inside HTTPStuff.cpp
This however makes a lot of errors popup when trying to run the program.
Like "missing ';' before identifier 'response'", and it all just seems weird to me.
If HTTP is defined, then include HTTPStuff.cpp which contains HTTP_POST_REQUEST.
I must be missing something, but what?

include <iostream> issue the application unable to start correctly (0xc000007b)

When I started to use VS2013, I created just very basic application like this.
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Hello!";
return 0;
}
It crashed and when I commented out the #include <iostream> its no longer crash. I did several research on this error but nothing is suitable for my situation. This is the error :
Thanks for all your helps.
Once you create a new project, if you create it as an empty project I don't think you will face this issue. Then, you start it from scratch and you use int main() instead of that _tmain(...) and DO NOT EVER use using namespace std;
start a new EMPTY project and use something like this:
#include <iostream>
int main()
{
std::cout << "Hello World";
return 0;
}

MSVS 12, C++, command arguments not working

I'm using C++ in Microsoft Visual Studio 12. I want to pass command line arguments. I have tried listing them in the MSVS's Project/Properties/Debugging/Command Arguments field and I've also tried using the CLIArgsMadeEasy add on but it never works. argc is always 1 where, of course, argv[0] is the app path.
Example: given a program of fred.exe that I would like to launch with three args : a,b,c
i.e. the equivalent of a cmd window line of
fred.exe a b c
I specify the args in the provided edit boxes exactly as:
a b c
using either method described above (MSVS standard or CLIArgsMadeEasy) but when I run they aren't passed.
The code is:
#include <iostream> // for standard I/O
#include <string> // for strings
#include <iomanip> // for controlling float print precision
#include <sstream> // string to number conversion
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
...
I have tried this program in my visual studio and it works:
#include <iostream> // for standard I/O
#include <string> // for strings
#include <iomanip> // for controlling float print precision
#include <sstream> // string to number conversion
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
for(int i = 1; i < argc; i++)
{
cout << i << ":" << argv[i] << endl;
}
return 0;
}