I have a new project where I created a HelloWorld.cpp Source file.
But when I am running it in Start without dedugging mode (CTRL+ F5), it opens the console and closes automatically.
#include <iostream>
#include<stdlib.h>
#ifdef _WIN32
#define WINPAUSE system("pause")
#endif
using namespace std;
void main()
{
cout << "Hello, World!" ;
}
Mr. Patel, did you try using the second solution on that linked question and then tried to use the run without debugging option? The Visual Studio will only keep the command prompt open if you set the subsystem option in the linker to console. If it is not set, the window will close as soon as the program finishes running.
At any rate, note that this will only work if you run your program from inside Visual Studio, running your .exe directly will still have it close as soon as possible. If you want your program to wait on the user, you would need to do it yourself (at least as far as I know). A very simple solution would be to write your main function like this:
int main (int argc, char* argv[]) {
...//Your code goes here.
std::cout << "Enter any character to end the program.\n";
char end;
std::cin >> end;
return(0);
}
Note that to use the cin and cout streams, you should include the iostream header in your code.
Related
I'm trying to run this code and im a beginner at this im really struggling I don't know what to do.
NB: A "MinGW" version of Code::Blocks was used here.
#include <stdio.h>
#include <omp.h>
int main() {
printf ("Hello, world:");
#pragma omp parallel
printf (" %d", omp_get_thread_num ());
printf ("\n");
return 0;
}
Change a debugger setting in the following way.
From the Settings menu click on Debugger..., then on the left of the screen select Default, a debugger type. This should show Executable paths set to:
C:\MinGW\bin\gdb.exe
change this to:
C:\Program Files\Codeblocks\MinGW\bin\gdb.exe
You should then be able to use the debugger.
NB: Other Information
The above type of fix is required if you install the "MinGW" version of 'Code::Blocks 20.03' on Windows, using 'codeblocks-20.03mingw-setup.exe' ( the version relevant on 8th April 2021 , with the default installation type used ).
I am using Visual Studio 2013 professional update 5 on Windows 10. I have written a simple Hello World program listed below.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
When I rebuild this code for Win32 (Debug or Release) and then run it without debugging (CTRL + F5), the console appears but it takes about 10 to 15 seconds before the "Hellow World" appears. If I run the code again, without rebuilding, the console with "Hello World" appears immediately. This only happens when I set the platform to "Win32", whereas the configuration could be "Debug" or "Release".
On setting the platform to "x64" everything works fine. That is the console with "Hello World" appears immediately both for "Debug" and "Release".
This problem is quite frustrating so any kind of help would be really appreciated.
Currently I work with RPi2 and remote connection to NetBeans 8.1 on my laptop.
I can write programs, run it, debug it and go step-by-step through the lines. This tutorial helps me to setup this: Installing NetBeans For C++ Remote Development on A Raspberry Pi
First test: I tried a simple "Hello World" program like this:
#include <stdio.h>
#include <stdlib.h>
void main(void)
{
int i = 0;
printf("Hallo World!\n");
i++;
printf("Hallo World!\n");
i++;
printf("Hallo World!\n");
i++;
printf("Hallo World!\n");
i++;
}
and debug it stepwise with NetBeans. Result: Variable i increments fine, but no printf output comes up! If I run the program without debugging, all works fine. I tried additional fflush and so on but nothing works.
What way can I do to solve the problem?
OK, I found he answer by myself...
First: Disable buffering by
setbuf(stdout, NULL); // disable buffering on stdout
Next: Setup the project by: Right Click on the project name > Properties > Categories = "Run" and here Console type = "Standard output".
This works for me with stepwise debug every printf line-per-line.
Mike.F.
I have read the launching Jruby from Aptana Studio 3 on Windows XP thread (to be fair, I am on windows 7) and created the wrapper script ruby.bat (#C:\jruby-1.6.6\bin\jruby %* - MY particular path)
Tried naming it "just" ruby, ruby.sh whatever, but Aptana wont find it. From any windows shell (cmd) it works without a hitch.
Also tried copying the JRuby.exe to Ruby.exe. That still won't work. Linking ruby.exe to jruby.exe with the mklink command still wont work.
Looked around the internet, but all I found are dead ends.
Any fix to this? Can't be THAT rare a setup, THAT difficult, or can it?
I did that by a simple trick...
I created a c++ file ruby.cpp:
#include <cstdlib>
#include <iostream>
using namespace std ;
int main( int argc, char *argv[] ) {
string cmd = "jruby.exe" ;
for (int i = 1 ; i < argc ; ++i)
cmd.append( " " ).append( argv[i] ) ;
return system( cmd.c_str() ) ;
}
Compiled as ruby.exe and moved to C:\jruby-1.6.6\bin.
It works...
I am using microsoft visual studio to do C++.
I don't see std::err and std::out in the output console of the IDE.
Is there a way to redirect them ?
You can indeed redirect std::out and std::err. Simply right click on your project in the solution explorer and select Properties. Then select Configuration Properties -> Debugging and put the appropriate arguments into the Command Arguments field. For example, to redirect std::err to a file, I would type in 2> ErrorLog.txt.
The things you type in Command Arguments simply get appended as command line arguments when Visual Studio runs your program, just like you had manually typed them in to the console. So, the above example simply tells VisualStudio to run your program with the command <programName>.exe 2> ErrorLog.txt instead of just <programName>.exe.
I know this is an old thread but I can't help but giving the answer since I can't believe there still is no real answer. What you can do is redirect the cout to a ostringstream of your choice. To do this, derive a new class from streambuf that will send the stream to OutputDebugString (Lets call this class OutputDebugStream) and create an instance of the class, myStream. Now call:
cout.rdbuf(&myStream)
I used cout for an example. This same technique can be used with cerr, just call
cerr.rdbuf(&myStream).
Stdout is a little more difficult if you are not using cout. You can redirect stdout during runtime by using freopen(), but it must be to a file. To get this to redirect to the Debug screen is a little more difficult. One way is to use fmemopen() if it is available (it is not standard) and write a streambuf to output this data to the Debug screen. Alternatively, you can redirect to a file and write a stream to open as input and redirect to the debug stream. A bit more work, but I think it is possible.
I use the following macro for output to the visual studio console
#ifdef _MSC_VER
#include <Windows.h>
#include <iostream>
#include <sstream>
#include <opencv/cxcore.h>
#define DBOUT( s ) \
{ \
std::wostringstream os_; \
os_ << s; \
OutputDebugStringW( os_.str().c_str() ); \
}
#else
#define DBOUT( s ) \
{ \
std::cout << s; \
}
#endif
Now if I could only get it to work within a cuda kernel?!