Golang : flag provided but not defined error
Problem :
Your program uses flag.Parse()
function to parse the command line arguments and everything is working fine until you attempted to parse a negative value, For example, such as calculating quadratic equation.
./program -3.0 1.0
This will cause the flag.Parse() function to recognize it a flag parameter instead of negative value. How to fix this?
Solution :
Use os.Args
instead of flag.Parse
. For example, change
flag.Parse()
arg := flag.Arg(0)
to
arg := os.Args[1]
Happy coding and hope this helps!
See also : Golang : Get command line arguments
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+5.8k Swift : substringWithRange() function example
+5.5k Golang : How to determine if request or crawl is from Google robots
+9.6k PHP : Convert(cast) bigInt to string
+6.4k Golang : Handling Yes No Quit query input
+16.4k Golang : Read data from config file and assign to variables
+4.7k Fix yum-complete-transaction error
+12.5k Golang : Fix image: unknown format error
+4.9k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+29.5k Golang : Get local IP and MAC address
+3.7k Linux : How to set root password in Linux Mint