I want to make my vector, vector_list, not to have any duplicate data. Here the code:
int is_Tally(int num )
{
vector<int> vector_list;
for(int i=1; i< 1000;i++)
{
int item = (i*num)%10000;
if (vector_list.empty())
{
vector_list.push_back(item);
}
else
{
if (find(vector_list.begin(), vector_list.end(), item)!=vector_list.end())
{
vector_list.push_back(item);
if (vector_list.size()>15)
{
return 0;
}
}
}
}
return vector_list.size();
Run Code Online (Sandbox Code Playgroud)
And I got an error when I execute the code.
error: no matching function for call to 'find(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, …Run Code Online (Sandbox Code Playgroud) 如何在C++中访问字符串索引?例如:如果我有字符串变量名称测试,我想从索引号5到9访问它.我怎么能用C++做到这一点?
string test;
cout<<test[5:9];
Run Code Online (Sandbox Code Playgroud)
我尝试了上面的方法,但它不起作用.有什么建议?谢谢.
<?php
require_once 'database.php';
class User {
public $id;
public $username;
public $first_name;
public $last_name;
public $password;
public static function find_by_id($id){
$result_array = self::find_by_sql("SELECT * FROM users WHERE id = {$id} LIMIT 1");
return !(empty($result_array))? array_shift($result_array): false;
}
public static function find_by_sql($sql){
global $database;
$result = $database->query($sql);
$object = array();
while ($row = $database->fetct_array($result)){
$object[] = self::instantiate($row);
}
return $object;
}
public static function instantiate($record)
{
$object = new self;
foreach($record as $attribute => $value)
{
if ($object->has_attribute($attribute)){
$object->$attribute = $value; …Run Code Online (Sandbox Code Playgroud)