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
+16.5k Golang : Delete files by extension
+5.2k Responsive Google Adsense
+9.7k Golang : Detect number of active displays and the display's resolution
+20.4k nginx: [emerg] unknown directive "passenger_enabled"
+11.9k Golang : Convert(cast) bigint to string
+20.5k Golang : Pipe output from one os.Exec(shell command) to another command
+18k Golang : Check if a directory exist or not
+7.4k Golang : Scanf function weird error in Windows
+4.6k Javascript : Detect when console is activated and do something about it
+6.9k Fix sudo yum hang problem with no output or error messages
+4.7k Chrome : How to block socketloop.com links in Google SERP?
+17.3k Golang : How to tell if a file is compressed either gzip or zip ?