我想使用迭代器打印矢量:
<?php
session_start();
if (isset($_REQUEST['submit'])) {
$number = $_REQUEST['number'];
if (!isSet($_SESSION['number'])) {
$_SESSION['number'] = array();
}
array_push($_SESSION['number'], $number);
/* foreach($_SESSION['number'] as $key => $val) {
echo $key . ">" . $val;
}
*/
var_dump($_SESSION['number']);
}
?>
<html>
<head>
<title>13.13</title>
<body>
<h2> Inputting numbers into array through form</h2>
<br>
<br>
<form method="post" action="#">
<input type="text" name="number" />
<input type="submit" value="submit" name="submit" />
</form>
</body>
我收到此错误:
DECLARE @Table1 TABLE (
Company_ID INT,
Person_ID INT,
[Name] VARCHAR(MAX),
Departement_ID INT
)
INSERT INTO @Table1
VALUES
(1,1,'aaa',1),
(1,2,'bbb',1),
(1,3,'ccc',1),
(1,4,'ddd',2),
(2,5,'eee',1),
(2,6,'fff',2),
(2,7,'ggg',2)
DECLARE @Departement INT = 1
SELECT
Company_ID,
MAX(CASE WHEN seqnum = 1 THEN Person_ID END) AS Contact1ID_Dpt,
MAX(CASE WHEN seqnum = 1 THEN [Name] END) AS Contact1Name_Dpt,
MAX(CASE WHEN seqnum = 2 THEN Person_ID END) AS Contact2ID_Dpt,
MAX(CASE WHEN seqnum = 2 THEN [Name] END) AS Contact2Name_Dpt
FROM
(SELECT
t.*,
ROW_NUMBER () OVER (PARTITION BY Company_ID ORDER BY Person_ID) AS seqnum
FROM
@Table1 t
WHERE --add your department filter here.
Departement_ID = @Departement
) t
GROUP BY
Company_ID;
你能帮帮我吗?
我想我正在转换我在int类型中收到的字符串。也许我没有以正确的方式使用迭代器(我认为这是问题,但我真的不知道)
提前致谢。
答案 0 :(得分:7)
如果你想在矢量中打印int
,我猜你想要使用:
for (vector<int>::iterator it = start.begin() ; it != start.end(); ++it)
cout << "\t" << *it;
注意我使用*
将迭代器it
更改为当前迭代的值。我不明白你试图用j
上的循环做什么,所以我把它丢弃了。
答案 1 :(得分:0)
在您更新的代码中
10/19/2015 10 122
您没有取消引用cout << "\t" << it;
并且没有输出it
的函数,因此您收到编译器错误。将代码更改为
vector<int>::iterator
应该修理它。
作为一个侧面,什么是嵌套for循环?