C++ 字符串/整数向量-cout

C++ 字符串/整数向量-cout,c++,vector,C++,Vector,我试图制作一个程序,要求用户输入10个人吃的煎饼,然后列出它们。人们的名字和吃的煎饼被储存在不同的载体中。打印向量中的值时出错 #include <iostream> #include <bits/stl_vector.h> #include <bits/stl_bvector.h> using namespace std; int main() { vector<int> pancakes; vector<string&

我试图制作一个程序,要求用户输入10个人吃的煎饼,然后列出它们。人们的名字和吃的煎饼被储存在不同的载体中。打印向量中的值时出错

#include <iostream>
#include <bits/stl_vector.h>
#include <bits/stl_bvector.h>

using namespace std;

int main() {
    vector<int> pancakes;
    vector<string> name;
    int temp_num;
    for (int x = 0; x < 10; x++) {
        cout << "Enter pancakes eaten by person " << x+1 << endl;
        cin >> temp_num;
        pancakes.push_back(temp_num);
        name.push_back("Person " + x);
    }
    for (int x = 0; x < 10; x++){
        cout << name[x] << " ate " << pancakes[x] << " candies." << endl;
    }
    return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main(){
矢量煎饼;
载体名称;
int temp_num;
对于(int x=0;x<10;x++){

不能添加
std::string
int
,因此这是不允许的

name.push_back("Person " + x);
但是,您可以使用,然后连接

name.push_back("Person " + std::to_string(x));
另外,我不确定为什么您有
包含,您应该只有

#include <iostream>
#include <string>
#include <vector>
#包括
#包括
#包括

不能添加
std::string
int
,因此这是不允许的

name.push_back("Person " + x);
但是,您可以使用,然后连接

name.push_back("Person " + std::to_string(x));
另外,我不确定为什么您有
包含,您应该只有

#include <iostream>
#include <string>
#include <vector>
#包括
#包括
#包括

不能添加
std::string
int
,因此这是不允许的

name.push_back("Person " + x);
但是,您可以使用,然后连接

name.push_back("Person " + std::to_string(x));
另外,我不确定为什么您有
包含,您应该只有

#include <iostream>
#include <string>
#include <vector>
#包括
#包括
#包括

不能添加
std::string
int
,因此这是不允许的

name.push_back("Person " + x);
但是,您可以使用,然后连接

name.push_back("Person " + std::to_string(x));
另外,我不确定为什么您有
包含,您应该只有

#include <iostream>
#include <string>
#include <vector>
#包括
#包括
#包括

非常肯定
“Person”+x
不会做你认为它会做的事。请向我们展示整个错误消息。(还有,为什么你要包括
而不是标准的
?)非常肯定
“Person”+x
不会做你认为它会做的事。请向我们展示整个错误消息。(还有,为什么你要包括
而不是标准的
?)非常肯定
“Person”+x
不会做你认为它会做的事。请向我们展示整个错误消息。(还有,为什么你要包括
而不是标准的
?)非常肯定
“Person”+x
不会像您认为的那样执行操作。请向我们显示整个错误消息。(另外,为什么您要使用
而不是标准的
?)但是…但是…我不喜欢字符串流:(@Cyber
boost::lexical_cast
)和+1,如果你使用OP:P这样的内部boost头进行操作。但是说真的,即使你说这是不允许的,代码也会编译,所以你应该解释OP代码中发生了什么。一个小错误-
“Person”
不是std::string
。但是……但是……我不喜欢字符串流:(@Cyber
boost::lexical_cast
)和+1,如果你使用OP:P这样的内部boost头进行操作。但是说真的,即使你说这是不允许的,代码也会编译,所以你应该解释OP代码中发生了什么。一个小错误-
“Person”
不是std::string。但是……但是……我不喜欢字符串流:(@Cyber
boost::lexical_cast
)和+1,如果你使用OP:P这样的内部boost头进行操作。但是说真的,即使你说这是不允许的,代码也会编译,所以你应该解释OP代码中发生了什么。一个小错误-
“Person”
不是std::string。但是……但是……我不喜欢字符串流:(@Cyber
boost::lexical_cast
)和+1,如果使用OP:P之类的内部boost头进行操作。但说真的,即使你说这是不允许的,代码也会编译,所以你应该解释OP代码中发生了什么。一个小错误-
“Person”
不是
std::string