Not sure what's wrong with my simple code

agolangf · · 411 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p><a href="http://pastebin.com/Hh7nFwV9" rel="nofollow">http://pastebin.com/Hh7nFwV9</a></p> <p>I got two errors when I ran it. Something wrong with using</p> <pre><code>list.Remove(i) </code></pre> <p>and </p> <pre><code>if list[i] == x </code></pre> <p>If you see anything else wrong with my code, please let me know. First time using Go.</p> <hr/>**评论:**<br/><br/>nosmileface: <pre><p>Use round brackets on import statement: <code>import (</code>...</p></pre>aylobng: <pre><p>Well that was silly. Thanks! I also ran into some more problems with my code if you could take a look.</p></pre>Fwippy: <pre><p>There&#39;s quite a lot of little things going on that are keeping your code from compiling. It&#39;s pretty clear what you&#39;re trying to do, but it looks like you&#39;re trying to do it the same way you did it in [whatever language you used before].</p> <p>I&#39;d recommend starting with a Go tutorial, and working from there. You might like to try <a href="https://tour.golang.org/welcome/1" rel="nofollow">A Tour of Go</a> to learn the basics of the environment in an interactive format (where you can test changes to your code, then run them, and see what it does or if it works).</p></pre>aylobng: <pre><p>I fixed up a lot of silly mistakes and I put up my new code. Is there a simpler way to do this</p></pre>Fwippy: <pre><p>Here&#39;s a set of changes that seems to work on my end. <a href="https://play.golang.org/p/lJcvOThkNV" rel="nofollow">https://play.golang.org/p/lJcvOThkNV</a></p> <p>Note: This particular code won&#39;t run &#34;properly&#34; on the go playground, as the code executes in an environment where trying to read from <code>os.Stdin</code> always gives you an End-of-file. I added some simple error handling to illustrate this.</p></pre>aboukirev: <pre><p>You need to start thinking in the target language and its library. For example, if the symbol you want to skip is going to be single rune/character, read string from input, slice/get the first rune, and then pass that rune as a delimiter to ReadString in the subsequent loop. In that loop check for returned err and stop looping when it is io.EOF.</p> <p>Alternatively, start using Scanner instead. There are examples for Scanner in the documentation for the bufio package.</p></pre>nhooyr: <pre><p>You need to read some documentation man.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

411 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传