我刚开始学习C++.我只是玩弄它并遇到一个问题,包括逐字逐句输入字符串,每个单词用空格分隔.我的意思是,假设我有
name place animal
Run Code Online (Sandbox Code Playgroud)
作为输入.我想读第一个字,对它做一些操作.然后读取第二个单词,对其进行一些操作,然后读取下一个单词,依此类推.
我试着用这样的getline存储整个字符串
#include<iostream>
using namespace std;
int main()
{
string t;
getline(cin,t);
cout << t; //just to confirm the input is read correctly
}
Run Code Online (Sandbox Code Playgroud)
但是,我如何对每个单词执行操作并继续下一个单词?
此外,在谷歌上搜索C++时,我在许多地方看到,而不是使用"使用命名空间std",人们更喜欢用"std ::"编写所有内容.为什么?我认为他们做同样的事情.那么为什么要一次又一次地写它呢?


我已经有了圈子部分.我在div上设置了黑色的背景颜色.对于文本,我设置了:悬停为显示的颜色.我只是无法弄清楚如何设置一个:将鼠标悬停在div上以及周长量.
这是我的代码:
HTML:
<a class="cirlink" href="http://www.somesite.com">
<div class="circle">
<h2 class="textcolor">click<br> here</h2>
</div>
</a>
Run Code Online (Sandbox Code Playgroud)
CSS:
.circle
{
border-radius: 125px;
width:250px;
height:250px;
background-color:black;
margin:auto;
text-align:center;
}
.textcolor:hover
{
transition:1s;
color:#FF4800;
}
Run Code Online (Sandbox Code Playgroud)
另外,有没有办法在悬停时更改div的背景图像?
我在 PostgreSQL 中使用 Rails 4.2。我有一个Product模型和一个Purchase带有Product has many Purchases. 我想找到最近购买的独特产品。最初我尝试过:
Product.joins(:purchases)
.select("DISTINCT products.*, purchases.updated_at") #postgresql requires order column in select
.order("purchases.updated_at DESC")
Run Code Online (Sandbox Code Playgroud)
然而,这会导致重复,因为它试图找到对 ( product.idand purchases.updated_at) 具有唯一值的所有元组。但是我只想id在加入后选择不同的产品。如果产品 ID 在连接中多次出现,请仅选择第一个。所以我也试过:
Product.joins(:purchases)
.select("DISTINCT ON (product.id) purchases.updated_at, products.*")
.order("product.id, purchases.updated_at") #postgres requires that DISTINCT ON must match the leftmost order by clause
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为我需要product.id在order子句中指定,因为这个约束会输出意外的顺序。
实现这一目标的轨道方式是什么?
sql postgresql ruby-on-rails greatest-n-per-group ruby-on-rails-4.2
String a = "576055795";
long b = 10*Integer.parseInt(a);
long c = 10*Long.parseLong(a);
System.out.println(b); //Prints 1465590654
System.out.println(c); // Prints 5760557950
Run Code Online (Sandbox Code Playgroud)
他们为什么不同?
这是一个noob问题,对不起,我刚开始在c ++中使用向量.这是我正在努力的代码.
int main()
{
//some code
int n;
cin>>n;
vector <int> a(n+1,0);
int first=find(&a,d); //d has some value from the upper portion of the code
}
int find(vector <int>* a,int o)
{
int b=o;
while(a->b!=0)
b=a->b;
return b;
}
Run Code Online (Sandbox Code Playgroud)
Q1:为什么传递像find(a,d)这样的向量不像在数组中那样工作.
Q2:在find函数中,为什么我必须用"."访问向量元素.或" - >".不应该[b]工作吗?如果这是正确的方法那么为什么[b]在主函数中起作用?
问题3:代码有什么问题?当我编译时,我得到了错误
In function ‘int find(std::vector<int>*, int)’:
error: ‘class std::vector<int>’ has no member named ‘b’
Run Code Online (Sandbox Code Playgroud)
我理解错误,但是如何访问所需的元素?
提前致谢.:)