Yep, I"m a freaking noob! I broke "Hello World"!

Pages: 12
MinGW (Minimalist GNU for Windows) is actually a whole collection of GNU programs (not just a compiler) that have been ported to Windows and it does include a version of GCC (GNU Compiler Collection) that works on Windows, creating binaries for that platform. It is natural for both Dev C++ and Code::Blocks to use MinGW on Windows. While GCC in latest MinGW is either same version as on other platforms or close, the version of MinGW installed by the ancient Dev C++ is really ancient and deprecated by todays standards.
Ok, I'm back... here is exactly what i copied and pasted in...

"#include <iostream>
int main()
{
auto x = R"(Hello world!)";
std::cout << x;
}
" (minus the quotes)

The instructions said to put that in, I literally copied and pasted it in. Then hit the "Build and Run" button, and still get the "fatal error: iostream: No such file or directory" message.
Oh and someone asked what OS I'm running... Win7Pro64bit, SP1.
hey thats what im running! well, my windows partition anyways... what compiler are you using? gcc or g++? also, are you sure the R"(Hello world!)"; is correct? i think it needs to be R("Hello world!"); although, you dont have a function R defined. what tutorial are you using?
Ok, I looked and when I saved it the file type said "C\C++" so I assumed that is was saving it as the correct type. Apparently not, when I looked at the file properties there was only a ".c" after the file name, so I did a SaveAs, selected "All Files *.*", and manually typed in ".cpp". Now when I build and run I do not get the fatal error message... now it just doesn't like the "x" as a variable.
Ok, got the "x" issue fixed... didn't know that I had to go into the compiler settings each time to check the box "Have g++ follow the C++11 ISO C++ language standard [-std=c++11]". got that checked and hit run... boxed popped up, but it took about 10-12 seconds for the actual "Hello World" to to show up. Is that normal?
perhaps no

how about the second time you run it ?
Took even longer... say 15 sec. for it to come up. I'm thinking something this small should be almost instantaneous. Thoughts?
@Little Bobby Tables
That is valid. Search 'Raw String Literal' for more details.

@chuggins143
Its possible that your computer is just sluggish. <iostream> is a massive library, and it also needs to open the console window (a more difficult task than it sounds) as well as dynamically load in the runtime library and standard library, unless you compiled it statically.

Are you running it from within Code::Blocks? Running it from outside of Code::Blocks can be slightly faster load time, because Code::Blocks has its own wrapper program over the top of yours to pause the program when its done.

On a side note, if you go to Settings->Compiler... you can make it so that all your future compilations with a specific compiler (in this case, GCC) will use the C++11 standard (rather than the default of gnu98, which is C++98 with some GNU extensions).
Last edited on
NT3, so to see if i understand it right, is this like the triple quotes in python?
NT3
Yes I was running it from inside C::B... So I went and found the "application" and double clicked it... it flashed up on the screen and faded away almost instantly. Should it do that? (I"m thinking not)
Last edited on
@Little Bobby Tables
Basically. Its mostly used in regexes, because escaping all those backslashes otherwise becomes a pain.

@chuggins143
Are you running Windows or a Linux machine? On Linux, run it from the terminal. On Windows, go to Start->Run, type 'cmd' and then navigate to it from there (use cd to change directory, just type the name of the application to run). Alternately, on recent versions of windows, drawing the application into the cmd window from explorer allows you to just press <ENTER> and run it.
chuggins143 (7)
Ok, I'm back... here is exactly what i copied and pasted in...

"#include <iostream>
int main()
{
auto x = R"(Hello world!)";
std::cout << x;
}
" (minus the quotes)

The instructions said to put that in, I literally copied and pasted it in. Then hit the "Build and Run" button, and still get the "fatal error: iostream: No such file or directory" message.


"fatal error: iostream: No such file or directory"
This means you are building and compiling a file or project with .C when it should be .cpp
already solved and answered neonorange
When you manually run the program outside of Code Blocks as is, it will almost instantly close because nothing is specifying it to stay open. There's quite a few ways that you can keep this from happening. Most people just add system("PAUSE"); just before return 0; in their main function when starting out. I wouldn't recommend this. Alternatively, you can do this:

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int main(){
cout<<"Hello world!"<<endl;
cout<<"Press enter/return to close the program."<<endl;

int end;
cin>>end;
return 0;
}


This is probably the simplest way to do this without using system("PAUSE");. It works by causing the program to essentially wait for further input before closing. By the way, the second cout statement is completely optional. I recommend it so the user knows what to do when they get that far.
Registered users can post here. Sign in or register to post.
Pages: 12