<pre><code>package main
import "fmt"
func main() {
fmt.Printf("Hello, world.\n")
}
</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'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 "\n" 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 "\n" is interpreted as an actual new line character instead of '\' and 'n' 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 "go version", and "go env" make sure that it all looks correct.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传