Running the test code on Go's site provides compiler errors

agolangf · · 440 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<pre><code>package main import &#34;fmt&#34; func main() { fmt.Printf(&#34;Hello, world.\n&#34;) } </code></pre> <p>This is the code they provide for you on the site to test your Go compile. When I run it on the correct package, I get two compiler errors.</p> <pre><code>(my GOPATH)/hello/hello.go:6: newline in string (my GOPATH)/hello/hello.go:7: syntax error: unexpected string literal at end of statement </code></pre> <p>What do I do? I don&#39;t know a ton about Go troubleshooting, but in the online REPL, it compiled just fine. Thoughts?</p> <hr/>**评论:**<br/><br/>Sighed: <pre><p>It sounds like you ended up with the &#34;\n&#34; in the string (2 characters) accidentally becoming an actual newline. Look at your own file and make sure that the string inside Printf is all on the same line.</p></pre>mibk: <pre><p>Looks like the &#34;\n&#34; is interpreted as an actual new line character instead of &#39;\&#39; and &#39;n&#39; characters.</p></pre>Injunire: <pre><p>I copy and pasted your example into play.golang.org and it worked fine with no modifications.</p> <p><a href="http://play.golang.org/p/wFwnLXN5W4" rel="nofollow">http://play.golang.org/p/wFwnLXN5W4</a></p></pre>djherbis: <pre><p>It compiled fine for me on 1.6. I guess check your &#34;go version&#34;, and &#34;go env&#34; make sure that it all looks correct.</p></pre>

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

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