我是C ++编程的新手。在一个教程中,作者提到“ cin”如果在字符串中读取一个空格,则会中断。如果要让程序读取整个带空格的字符串行,则应使用函数“ getline”。
但是,我无法使其工作。
这是我的代码:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string my_name;
cout << "Please enter your name: ";
getline(cin, my_name, "\n");
cout << "My name is " << my_name << " .";
}
Run Code Online (Sandbox Code Playgroud)
我正在使用的IDE是Xcode。错误消息是“没有匹配的函数来调用'getline'”。
我已经搜索了类似的问题,但是在我看来,没有一种解决方案适用于我的问题。也许我缺少一些知识?谢谢。
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Girl! Fly and eat the yogurt!</title>
<script src="js/easeljs-0.8.1.min.js"></script>
<script src="js/sketch.js"></script>
<script src="jquery-1.11.3.min"></script>
<link rel="stylesheet" href="css/particles.css">
<style type="text/css">
#frame {
position: relative;
text-align: center;
margin-top: 100px;
}
</style>
</head>
<body>
<div id = "frame">
<canvas class=" sketch" height="385" width="1440"></canvas>
</div>
<script src="js/particles.js"></script>
<script>
var canvas = $("#frame").get(0);
canvas.id = "gameView";
</script>
<script src="js/app.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在这种特定情况下,您能告诉我如何使用 jQuery 或 vanilla JS 在 div 中获取画布吗?以及如何为捕获的画布元素设置 id?