static_assert(__clang__ && __cplusplus >= 199711L, "Your compiler is not supported.");
#include <iostream>
/// Triple slash to include in auto-generated documentation
int main()
{
// test comment (two slashes to exclude from auto-generated documentation)
int x = 0;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
auto y = {1, 2};
#pragma clang diagnostic pop
std::cin >> x;
for (int z = 2; z != 10; ++z)
{
std::cout << z << " times\n";
}
std::cout << std::endl;
}
* Reason being that I'm trying to force as many people as possible to switch to the obviously superior cross-platform compiler. :)
#include <iostream>
#include <vector>
int main()
{
int x = 0; //test comment
std::vector<int> y = {1, 2};
std::cin >> x;
for (int z = 2; z < 10; ++z)
{
std::cout << z << std::endl;
}
}
My C++ is rusty. I honestly been spending too much time doing UnrealScript. I hope in UE4 the C++ code support is not going to be too Unreal Engine specific or far off from actual C++ code.
So I'd probably write that code like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
int main() {
//test comment
int x = 0;
int y[2] = { 1, 2 };
std::cin >> x;
for(int z = 2; z < 10; z++) {
std::cout << z << std::endl;
}
}
And if it was longer then I'd probably add in "using namespace std;" at the top.
#include <iostream>
namespace{
/* Type conversion function. I use this so that I can basically treat all data
input and output as characters.*/
template<class type1, class type2>
inline type2 conv(const type1& t1)
{
std::stringstream ss;
type2 t2;
ss<< t1;
ss>> t2;
return t2;
}
}
int main()
{
usingnamespace std; //namespace for only this function.
int an_int(0);
int arr[2] = {1, 2};
{
string temps("");
cin.rdbuf()->in_avail(); /*remove anything in the buffer. We want to make sure that the user
enters somthing*/
cin>> temps;
an_int = conv<string, int>(temps);
}
for(short x = 2; x < 11; x++) cout<< x<< " "<< ((x != 1) ? "times" : "time")<< endl;
}
It really depends on what I'm doing and whether I'm being lazy or not. I use std::, but if I'm being lazy (testing something) I just do usingnamespace std;