No output in eclipse (Linux GCC) - c++

I've compiled a c++ file with Linux GCC compiler via eclipse , and it works fine without any error , but the problem that I face is that I cannot see any output from eclipse .
The code :
#include <iostream>
using namespace std;
int main() {
char reverseMe[] = {"reverseText"};
for(int v = sizeof(reverseMe) ; v >= 0 ; v--){
cout << reverseMe[v] << flush;
}
return 0;
}
In addition , I've launched the same code in online-c++-compiler , and it works fine and it gives me the result ! , but in eclipse , no output at all..
However , if I just replace 'flush' with 'endl' it gives me the result each character per one line (in eclipse),but I want the result to be in only one line.
So where is the problem ?
NOTE: I'm using Ubuntu 14 LTS , 64 bit

Related

SYCL program working using VS Debugger but not when running the .exe

I am trying to build and run a simple SYCL program from this book. Here it is:
#include <CL/sycl.hpp>
#include <iostream>
using namespace sycl;
const std::string secret {
"Ifmmp-!xpsme\"\012J(n!tpssz-!Ebwf/!"
"J(n!bgsbje!J!dbo(u!ep!uibu/!.!IBM\01"
};
const auto sz = secret.size();
int main(int argc, char* argv[]) {
queue Q;
char* result = malloc_shared<char>(sz, Q);
std::memcpy(result, secret.data(), sz);
Q.parallel_for(sz, [=](auto& i) {
result[i] -= 1;
}).wait();
std::cout << result << "\n";
return 0;
}
I am using Visual Studio 2019 and I am compilating with Intel oneAPI DPC++ 2022. If I run the Visual Studio Debugger, everything is working, I am obtaining as output:
"Hello World! I'm sorry, Dave. I'm afraid i can't do that. - HAL"
But if I am executing the .exe file that I just have built from the command prompt, nothing is happening... The program is executing itself, nothing is given as output, and I receive no error either. I tried to put some printf everywhere to see where to problem could come from. If I put a printf right just after "queue Q;" I wouldn't be able to see it when I run the .exe file.
From what I have read the problem comes from the initialization of my object Q. I replaced "queue Q;" by "queue Q(default_selector{});" but it didn't solve the problem.
EDIT : I have simply reduced the code to the following:
#include <CL/sycl.hpp>
#include <iostream>
using namespace sycl;
int main(int argc, char* argv[]) {
std::cout << "Beginning of the program.\n";
queue Q; // The problem appears to come from this line
std::cout << "End of the program.\n";
system("pause");
return 0;
}
Here is the output when I am launching the program in the Visual Studio Debugger:
> Beginning of the program.
> End of the program.
>
> Sortie de C:\Users\...\test.exe (processus 8108). Code : 0.
> Press any key to continue . . .
Here is the output when I am calling the .exe from the command prompt:
> C:\Users\...\Release>test.exe
> Beginning of the program.
>
> C:\Users\...\Release>
I have noticed that during the short time when the program is running in the command prompt (something like one second), I saw that the program Windows Problem Reporting ran in the Task Manager. Than it vanished as soon as the program apparently finished to compute.
EDIT 2 : Here is what happens if I am looking for the device used. With the following code:
#include <CL/sycl.hpp>
#include <iostream>
using namespace sycl;
int main(int argc, char* argv[]) {
default_selector device_selector;
std::cout << "default_selector has been defined.\n";
auto defaultQueue = queue(device_selector);
std::cout << "default_queue has been defined.\n";
std::cout << "Running on " << defaultQueue.get_device().get_info<info::device::name>() << "\n";
system("pause");
return 0;
}
I get this output from the Visual Studio debugger:
> Beginning of the program...
> default_selector has been defined.
> default queue has been defined.
> Running on Intel(R) Core(TM) i5-3337U CPU # 1.80GHz
> Press any key to continue...
And this when I am executing the .exe from the commande prompt (doing this in administrator or not doesn't change anything):
> C:\Users\...\Release>test.exe
> Beginning of the program...
> default_selector has been defined.
>
> C:\Users\...\Release>
The answer has been brought by the Intel Developer Software Forums.
Although the compiler has been well installed on my machine, the oneAPI environment had not be configured yet. This is why it couldn't work when running the .exe in the Windows command prompt.
I had to run the batch file setvars.bat that was at the adress C:\Program Files (x86)\intel\oneAPI then it worked!

C++, Same code won't work btw CLion & Visual Studio

I have the following code in VS:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inData;
int temp;
inData.open("test_file.txt");
do {
inData >> temp;
cout << temp << " ";
} while (!(inData.eof()));
inData.close();
return 0;
}
test_file.txt contains the following data (it's a single line):
1 2 3 4 5 6 7 8 9 0 10 11
When I built and ran this in VS, it worked fine. Today, when I tried to run it on CLion, it gives me garbage data. I tried creating a new project from scratch in CLion and copy-pasting just the code in main.cpp, but still gives me random data. And now I'm wasting my Saturday wrestling with my IDE instead of just finishing my homework. Any help?
I figured out what the issue is. CLion doesn't recognize the parameter as a path, whereas VS does.

%lf specifier gives wrong output for a double integer in codeblocks IDE while I added "aka C++17" flag with my IDE

After adding "aka C++17" flag on my codeblocks 17.12 IDE the code given below gives wrong output .
After facing this problem, when I removed "aka C++17" flag, output is correct, i again added the flag and the output is incorrect again.
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
double a,b,ans;
scanf("%lf%lf",&a,&b);
ans=a/b ;
printf("%lf\n",ans);
return 0;
}
I gave input 5 and 2 , the output is -0.000000 .
What is changed in "aka C++17"?

Simple output loop fails in Visual Studio Code terminal when compiled with cl

Consider the simple program, in file a.cpp:
#include <iostream>
int main(int argc, char* argv[])
{
for (int i = 0; i < 10000; i++)
{
std::cout << i << std::endl;
}
}
It works fine when I run it in the Visual Studio Code (Powershell) terminal after compiling it on Windows with Cygwin g++, like so:
g++ a.cpp -o a.exe
However, I get strange and inconsistent behavior when I run it after compiling it with cl like so (in a separate program, the Developer Command Prompt for VS 2017):
cl a.cpp
When run in the Visual Studio Code (Powershell) terminal after compiling it this way, it stops outputting numbers well before 9999. Furthermore, it stops outputting at a different point each run. Running the program from a .bat script to check the %errorlevel% indicates that the error code is 0, so it doesn't seem to be crashing during the loop.
This, on the other hand, works totally fine from the VSCode terminal when compiled with cl, outputting 9999 every time:
#include <iostream>
int main(int argc, char* argv[])
{
int j = -1;
for (int i = 0; i < 10000; i++)
{
j++;
}
std::cout << j << std::endl;
}
So it seems like code compiled with cl will just stop outputting data written to std::cout after a little while when run from the Visual Studio Code terminal. But why would that happen?
Update
It works perfectly after compiling with cl when running from Developer Command Prompt for VS 2017, or from Powershell, or from Command Prompt. It only has the strange behavior when (a) compiled with cl instead of g++ and (b) run from a Powershell terminal within VSCode.

very basic regex scenario works different than my expectation on libstdc++-v3

I'm getting a different behavior than my expectation (and also different than Microsoft C++).
Consider the following test.cpp file:
#include <iostream>
#include <ostream>
#include <regex>
int main( void )
{
std::regex rx( "a(b+)(c+)d" );
std::string s( "abbbbccd" );
std::smatch m;
bool f = regex_match( s, m, rx );
std::cout << std::boolalpha << f << std::endl;
if( f ) {
std::cout << "m[1]=" << m[1] << std::endl;
std::cout << "m[2]=" << m[2] << std::endl;
}
return 0;
}
On my Ubuntu Oneiric box, note how I compile the program, and note the output I'm getting from a.out:
$ g++ -std=c++0x test.cpp
$ ./a.out
true
m[1]=abbbb
m[2]=bcc
On the other hand, on my Windows machine, using Visual Studio 2010 I've:
C:> cl /EHsc test.cpp
C:> test.exe
true
m[1]=bbbb
m[2]=cc
I'm not an expert, but Microsoft Visual Studio seems to be the correct answer. This is a very basic scenario, so I wonder what is going on. I can't believe it's a bug, and I can't believe its a fundamental disagreement between MS and GNU at such a basic level. I suspect something in my configuration or in my command line. I got my g++ compiler and headers after installing the default Ubuntu 11.10 client, and 'apt-get install build-essentials'.
Could be a compilation switch that I'm missing, or a fundamental disagreement between MS and GNU
<regex> is still largely unimplemented in libstdc++: http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011