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"
Related
I have to write a program that allows the user to input a name from the keyboard. The program should then read from the file and search for matching name among the girls and boys. If a match is found it should output the rank of the name. The program should also indicate if there is no match.
Here is my program :
ifstream fin;
fin.open( "/Users/fashiontekk/Downloads/Assignment 3 Instructions/babyNames2017.dat" );
string nameInput;
string boyName;
string girlName;
int rank= 0;
int boyRank= 0;
int girlRank =0;
cout << " Which name would you like to check? < no space in names please > " << endl;
cin >> nameInput;
fin >> boyName;
fin >> girlName;
rank++;
cout << " After going through an extensive search here is what we found out - " << endl;
if (nameInput == boyName) {
cout << nameInput << " is ranked " << rank << " in popularity among boys. " << endl;
boyRank = rank;
}
if (nameInput == girlName) {
cout << nameInput << " is ranked " << rank << " in popularity among girls. " << endl;
girlRank = rank;
}
if (boyRank < 1 || boyRank > 1000) {
cout << nameInput << " is not ranked among the top 1000 boys name. " << endl;
}
if (girlRank < 1 || girlRank > 1000) {
cout << nameInput << " is not ranked among the top 1000 girls name. " << endl;
}
cout << " Hope that is the result you were looking for ... Ending program. " << endl;
fin.close();
return 0;
}
However, my output window says : Which name would you like to check? < no space in names please >
Program ended with exit code: 0Liam
After going through an extensive search here is what we found out -
Liam is ranked 1 in popularity among girls.
Liam is not ranked among the top 1000 boys name.
Hope that is the result you were looking for ... Ending program.
I tried to type in Liam which the most popular boys name according to the file provided. I feel like my coding is right however I can't spot the error.
It is my first year in Computer Science and I don't can't find my mistake.
OK, we've all been there at some point. You need to work on your debugging skills — you're gonna need them. In particular, spend some time learning to use gdb or whatever debugger you have available. A good debugger will let you step through a program a line at a time, watch variables, and generally checkout every possible thing that could be a problem.
So let's take a look at your code with an eye toward debugging it. It's handy that the message that's emitted comes right up near the top of the program — that really narrows down the places where you could be going wrong. Here's the first part of your program:
ifstream fin;
fin.open( "babyNames2017.dat" );
if (!fin) {
cout << " File not processed ";
return 0;
}
So, the first line just declares the variable for your input file. There's not much that can go wrong there. The next line opens the file... hmmm... I'm not sure if that might be a problem or not, so let's stick a pin in it for now and keep going. The next line, if (!fin) {, is a condition that only succeeds if !fin is true, which means that fin must evaluate to false to enter this block. And it clearly does enter this block, because that's the part of the code that emits the "File not processed" message. So fin must be 0, right? OK, so how can fin possibly be 0?
I don't have the C++ iostreams documentation handy, but you should go look up what that fin.open(...) call does if it fails. Given the way you've written the code, it looks very much like you'd expect failure to set fin to 0, right? So how can that call fail? Well, for starters, you're only supplying the file name... the working directory when you run the program might be set to something you don't expect, so the file isn't found. Or the file name might not match the name of the actual file. Remember that some file systems are case sensitive, and if you're working with such a file system then the open call will fail if the file is just named babynames2017.dat or BabyNames2017.dat or anything else that doesn't exactly match your file.
This question already has answers here:
How to get the current user's home directory in Windows
(4 answers)
Closed 7 years ago.
So I know how to make it, I just want it to open the file without specifying the path.
For example: I have it in
C:\Users\\(me)\Desktop\Projects\BCs\BSCV2\bin\Debug\BSC.exe
but if I give it to a friend, he has a different username, (him) for example, so the command won't be able to execute even if he has it on his desktop because the path isn't valid anymore.
Here's a part of the code:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int a;
cout << endl;
cout << " This window is used for launching the programs." << endl;
cout << " Type in the number of the program you want to use and press Enter." << endl;
cout << endl;
cout << " 1) BSCV2 << endl;
cout << endl;
cout << " "; cin >> a; cout << endl;
cout << endl;
if (a == 1){
system ("start C:\\Users\\(me)\\Desktop\\Projects\\BCs\\BSCV2\\bin\\Debug\\BSCV2.exe");
system ("pause");
}
return 0;
}
How can I make it run on anyone's PC, regardless of where they put it?
Also, if you could re-write my code as an example, I'd appreciate it.
You will need to get the "home" directory for the current user logged in. Reference this post: How to get the current user's home directory in Windows, or this one: How can I find the user's home dir in a cross platform manner, using C++?
However, are you absolutely sure that all users (on their respective machines) running your application will have the exact directory path to the executable you're trying to call (\Desktop\Projects\BCs\BSCV2\bin\Debug\BSCV2.exe)?
You may be better off writing a function to search for the executable, or ask the user to specify where it is.
So if I write a piece of code like this:
string name, feeling;
cout << What is your name?" << endl;
cin >> name;
cout << "Hello, " << name << "!"<<endl;
cout << "So how are you feeling today?" << endl;
cin >> feeling;
I get the output:
What is your name?
James (input from user)
Hello, James!
So how are you feeling today?`
But I want it to remove the first message and the input, so the user will get just this on the console window:
Hello, James!
So how are you feeling today?
As long as you stay on the same line, it's usually pretty easy to use a combination of \b (back-space) and/or \r (carriage return without new-line) and some spaces to go back to the beginning of a line and write over what's displayed there.
If you need to do (much) more than that, you can use the Windows console functions such as SetConsoleCursorPosition and FillConsoleOutputCharacter to write data where you want it, overwrite existing data, etc.
If you care about portability to Linux and such, or already know how to program with curses, you might prefer to use PDCurses instead. This is basically a re-implementation of the ncurses programming interface on top of the Windows console functions.
If you work on windows environment, try this
#include <iostream>
int main()
{
std::cout << "This is the first line";
system("cls");
std::cout << "This is the line on clear console" << std::endl;
return 0;
}
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.
I wanted to start learning how to program, so I asked my math professor if he had a book that I could borrow. He did and so I have been reading a C++ book from ~1994 (it still has a floppy disk :P). Anyway, I made it to a point in it and it sets up a program that calculates y in y=mx+b. Pretty simple, but I decided to try it out and it is not working. I would really like to figure out why it is not working and fix it.
Here is the code for it:
#include <iostream>
using namespace std; //not in the book: added by me after some Googling
int main() {
cout << "Input m: " << flush;
int m;
cin >> m;
cout << "Y-intercept: " << flush;
int b;
cin >> b;
cout << "X coordinate of interest: " << flush;
int x;
cin >> x;
int y;
y = m * x + b;
cout << "y = " << y << "when m = " << m << "; " << "b = " << b << "; x = " << x << endl;
}
edit: Sorry. Forgot to describe what was going on. lol. The program executes properly until it it comes to displaying the final line. After submitting "X coordinate of interest: " the program simply exits. I mean I am no expert in C++, but should the final cout write to the console?
And I know it is really outdated, but I really just want a platform to stand on when I begin to look at the newage languages. The book itself is only about 700 pages, and there is a LOT of explaining in it, so it is not very much code wise. I have probably 10 to 20 700 page pdfs on Java and C#/C++/C all written within the past six years. So I'll be good. Just want a starting point. :) Plus this book explains a lot about how a computer works and certain jargon that some of the newer books just don't.
This is a common windows cmd problem. Either run the program through cmd, type in the executable name, or add getchar or cin >> variable to the end of the program.
Assuming this is in Visual Studio when you run a program with debugging (F5) the console instance is closed automatically. You can either add a input line to the end of the program as others have mentioned or run the program without debugging (Ctrl+F5) and the console window will pause and let you see the output at the end of the programs execution.