I installed codellite 7.0 yesterday and have been trying to work with it. But there seem to be some problem. I cannot run any code.
For now code is pretty simple.
#include <stdio.h>
int main(int argc, char **argv)
{
printf("hello world\n");
return 0;
}
however, it returns following and output is blank with Press any key to continue
Current working directory: D:\ .....
Running program: le_exec.exe ./1
Program exited with return code: 0
Your program is running fine, the only problem is that after the printf the program returns 0 and shuts down immediately, it does run and print out "hello world", you just don't have the time to see it.
To make the program wait for user input so that you can see the output use cin.get() :
#include <stdio.h>
#include <iostream>
int main(int argc, char **argv)
{
printf("hello world\n");
std::cin.get();
return 0;
}
Related
I'm programming in C++ with Netbeans 8.2 at school, these computers have Ubuntu 14.04 and gcc-4.3.
The cout randomly works altought it doesn't send any errors in the log.
Every computer here has the same problem.
main.cpp:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "Hello World!" << endl;
return 0;
}
Posible (and expected) output:
Hello World!
RUN FINISHED; exit value 0,; real time: 0ms; user: 0ms; system: 0ms
Other posible output:
RUN FINISHED; exit value 0,; real time: 0ms; user: 0ms; system: 0ms
Sometimes the compiler prints out and finish without being noticed. So you can use cin to check if that is happening to you.
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "Hello World!" << endl;
int test;
cin >> test;
return 0;
}
Here the compiler will wait for you to enter a value, so you will have plenty of time to see your output.
I solved this going to Project Properties -> Run -> Console Type -> Standard output
I search a lot but don't find nothing.
I want make a C++ software to run a software with argument in C++
Example : start putty -ssh user#server -pw password
start notepad -someargument
To start a different software than your own program (with or without arguments) you can use system() from <cstdlib> header.
#include <cstdlib>
int main(int argc, char* argv[]) {
system("start putty -ssh user#server -pw password");
return 0;
}
If you want to evaluate the arguments to your own program, you can use argv[]. argv[0] holds the name/path of your program, and argv[1] ... argv[argc-1] the actual arguments i.e.
#include <cstring>
#include <iostream>
int main(int argc, char* argv[]) {
if ((argc > 1) && (!strcmp(argv[1], "-help"))) {
std::cout << "Showing help" << std::endl;
}
return 0;
}
I made an Xcode project. Like this:
Mac OS X -> Application -> Command Line Tool
I chose C++
And then I saved it in a folder.
Now I opened it in Xcode, there is a file named main.cpp under the project name title, so I opened that.
So main.cpp contains (location: Desktop/CPP/learn/learn/main.cpp)
#include <iostream>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
Now I click on File > New File and I selected C++ file without header, I named it main1.cpp
So that main1.cpp now just has
#include <stdio.h>
I replaced that and made main1.cpp to
#include <iostream>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "MAIN1DOTCPP!\n";
return 0;
}
Then I ran main1.cpp, And the out put was "Hello World", I have been trying to get the output of the second file, That is "MAIN1DOTCPP" for like 2 hours now, Can someone please help?
I want to create a thread with ACE_thread_manager, there is no error when I debug. but the result is not right. The function did not work; code like this:
#include "ace/OS.h"
#include "ace/Log_Msg.h"
#include "ace/Thread_Manager.h"
#include <iostream>
void thread_start(void* arg)
{
std::cout << "Running thread..\n";
}
int main(int argc, char *argv[])
{
ACE_Thread_Manager::instance()->spawn(ACE_THR_FUNC(thread_start), 0, THR_NEW_LWP);
return 0;
}
this demo should print "Running thread.." , but when I debug it ,it print nothing . These Chinese mean "Please press any key to continue" .
You have to wait in your main until your workers threads have finished. As you say, you have to add the following line before the return in main.
ACE_Thread_Manager::instance()->wait();
I am building a web application / Interface for my C++ program which will be hosted on the server and then using a scripting language ("PHP") I will then execute the program to run.
I am using G++ to compile the code and and I execute the command to run like so: ("./main") now is it possible that I can pass in the file location so then my program can run? So for example like this:
int main(int argc, char *argv[], string* fileLoc)
{
// code
}
Then execute like this ("./main(FILE_LOCATION)")?
Hope someone can help
You should keep the standard main signature int main(int argc, char *argv[]). The filename would be in argv[1], provided you execute it like this:
./main somefilename.txt
//main.cpp
#include <iostream>
int main(int argc, char* argv[])
{
if (argc > 1)
std::cout << argv[1] << "\n";
}
./main Hello_there
Hello_there