unexpected % symbol after running cpp program in vscode terminal - c++

tried running code but I'm facing an unexpected "%" symbol at end of the output.
#include < iostream >
using namespace std;
int main()
{
cout << " abc " ;
}
please help!!!

That is most likely your shell telling you that the output did not place a newline. zsh and fish do this by default, I believe. The screenshot indicates macOS, which does use zsh as of Catalina.
If you don't want to see that, change your code to output a newline.
cout << " abc \n";

Related

VS Code exits without displaying any output when a character array is taken as input

I have tried updating my g++ installation but there has been no solution.
Here is the code.
#include <iostream>
using namespace std;
#include<string>
#include <cstring>
int main()
{
char str[100];
cout << "Enter a string: ";
cin>>str;
cout << "You entered: " << str << endl;
cout << "\nEnter another string: ";
cin>>str;
cout << "You entered: "<<str<<endl;
return 0;
}
The output that this code shows is:
Check the terminal
Please give me a solution or at least a reason for this. I am new to Stack Overflow so please free to correct me if I made any mistake in the post. [This problem only happens in vs code but works in online gdb compiler.]
Edit:After I tried executing this in the cmd line this what it shows
cmd line execution
The output you're seeing is from some kind of makefile. You didn't say how you're trying to build the file so it's hard to say what caused the issue.
However, you can simply compile your file directly by typing g++ hgg.cpp -o hgg in the command shell
After writing the code, switch to Command Prompt (Cntrl + x) move to the directory, in which the C++ program is present.
Then run the following:
g++ -Wall filename.cpp -o filename
If nothing is printed on the console, then your code is syntactically correct. Then do the following:
filename.exe
It should work now.

ShellExecute - ERROR code 5

I am using Notepad++ with TDM-GCC. My computer is 2Gb RAM Windows 10 32 bit 3.30 GHz. When I execute my simple program, it shows error.
Access is denied.
An attempt was made to execute the below command.
Command: D:\Deane\Github\CPP_Projects\AnalysisName\main.bat
Arguments:
Error Code: 5
Image of the error
I follow this: ShellExecuteEx function always returning error code 5 (C++)
Program's code (if necessary):
/* AnalysisName Program - written by Vo Tran Nha Linh */
#include <iostream> // Input and Output library.
using namespace std;
int main()
{
string name;
cout << "Hello friend! It's nice to meet you, what is your name?" << endl; // Ask the name.
cin >> name; // Input name.
cout << "Hello " << name << ". Your name is interesting." << endl; // Have a greeting.
cout << "Your name has " << name.length() << "letters." << endl; // Show the name's length.
cout << "It starts with " << name.front() << "letter." << endl; // Show the first letter of the name.
cout << "It ends with " << name.back() << "letter." << endl; // Show the last letter of the name.
return 0;
}
But it doesn't active, please give me a help. Thank you very much!
My problem solved!
I miss Visual C++ Redistributable 2008 and 2010.
Moderators please close my topic. Thank you!
Navigate to C:\Program Files (x86)\Notepad++ Right mouse click the Notpad++.exe file click properties & under the compatability Tab UN-TICK run the program as administrator box DONE.
Refer to this link.
this solved it for me:
right click on the file that won't run (in my case a .cmd file)
check the 'Unblock' checkbox next to the remark "This file came from another computer and might be blocked to help protect this computer"

C++ (g++) special characters encoding ('\a', '\b', etc.)

I am using g++ version 4:4.8.2-1ubuntu6 with Eclipse 3.8 on Linux Mint.
Following example from my C++ book does not work as expected:
//bondini.cpp -- using escape sequences
#include <iostream>
int main()
{
using namespace std;
cout << "\aOperation \"HyperHype\" is activated\n";
cout << "enter sercret code:________\b\b\b\b\b\b\b\b";
long code;
cin >> code;
cout << "\aYou entered: " << code << "...\n";
cout << "\aCode OK! Commencing Z3!\n";
return 0;
}
I get following result when running the program:
In Eclipse and directory I am using UTF-8 encoding. Why does not '\a' play sound as it should and '\b' does not move the cursor one space back, while '\n' works properly.
edit: As I understand it, it is the compiler that makes the mess of it. --> I was wrong, in terminal it works fine, but eclipse 'terminal' does not work.
Wherever you are sending your output. What the destination does with it is entirely in its own hands. So while eclipse might not support these special characters your terminal should.

Visual Studio 2012. "unable to start program" *.exe "cannot find the file specified"

Yes, I know this is a common question. No other question/answer sets meet my needs here. Taking c++ this quarter. Been going along just fine. Trying to do last assignment, and I'm getting the above error, even on a fresh project with:
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
cout << "hello world" << endl;
}
As an experiment, I tried pasting in much more elaborate code from previous assignments. This runs. Just pasting in -- not running the previous assignment.
I took the simplest of them, and stripped it down to this:
Main.cpp:
#include <iostream>
using namespace std;
int main()
{
double hours, rate;
cout << "Hello World";
cin >> hours;
cout << "Hello World";
cin >> rate;
system("pause");
return 0;
}
This compiles and runs fine. However, if I remove either of the cin lines I get the error stated in the title.
I'm just flabbergasted because pasted in code compiles and runs, but even "Hello World" in a fresh project won't.
Does my above example provide any clues?
Does it happen if you run it as administrator? Were you running it from Visual Studio or did you clicked the executable?
If you have an anti virus, it may be causing the error as well.

cout behaving unexpectedly for specific strings

This question is an extension to this one.
Eclipse Debug run and console run of the same program give different outputs
To give a bit of background...
While parsing the output of the NTP application I discovered something rather odd in my string outputs. The environment that I am using is eclipse with CDT in Debug mode, redirecting console output to a terminal (/dev/pts/0) with fish running as shell.
Where is what I found...
Strings with starting characters or charachter within like *, +, &, ^. such as when I try to cout like this.
cout << "+123" << endl; //does not get printed
cout << "*123" << endl; //does not get printed
cout << "&123" << endl; //Concatenates with string below (without the line feed)
cout << "|123" << endl; //^
cout << "^123" << endl; //Does not get printed
Also
cout << "abcdef" << endl << endl;
does not have the desired effect of two linefeeds; only one gets printed.
Whereas when I run the progam through the terminal...
~$ ./Project/Debug/Project
Everything is normal and works as expected.
Is this expected behaviour, something I am not aware of?
Or is this a bug, corruption or something if such nature?
Or am I doing something wrong?
P.S: I might have left some details out by accident, please read the question in the link provided about to catch up.