我正在尝试将 int 值插入字符串,而不是 1,我得到 10
I am trying to insert int values into string and instead of 1 i get 10
我有 1005 个节点,所以我在这里输入 1005 和值 1 到 1005 通过循环 即使我手动输入,我也得到相同的打印
void call()
{
int x;
cout << "Enter Number of characters"; string s;
cin >> t;
cout << "Enter char names :";
for (int i = 0; i < t; i++)
{
x = i + 1;
str1 = to_string(x);
//cin >> str1;
insertd(str1);
}
}
void insertd(string n) {
node *ptr = new node;
ptr->name = n;
if (head == NULL) {
head = ptr;
last = ptr;
}
else {
last->down = ptr;
last = ptr;
}
}
当我在这里使用此部分打印时
void print() {
current = head;
node *p;
while (current != NULL) {
p = current;
while (p != NULL) {
cout << p->name << p->weight << " ";
p = p->next;
}
cout << endl;
current = current->down;
}
}
我得到的结果是 10,20,30 而不是 1,2,3
如果您使用 std::to_string 进行转换,则不应打印 10 而不是 0。 您可以尝试仅打印名称吗?
std::cout << p->name << std::endl
你的p->权重肯定为0。
相关文章:
- C++ - 最坏情况和平均情况插入时间复杂度在 std::unordered_map <int,int>?
- 我正在尝试将 int 值插入字符串,而不是 1,我得到 10
- 如何在 std::map<const int、int> C++ 中重载插入运算符>>?
- 如何在一对集合的向量中插入元素?vector<pair<int,set<string>>>
- 有没有办法通过插入新类型名称而不是 int 来使用 2 位大小类型而不是 int?
- 如何在'char'中转换和插入'int'以进行C++?
- c++:无法将 pair<int、MLine*> 插入到unordered_map
- 将int/char插入数据库
- Bool排序的插入函数,检查列表中是否已经存在int
- 插入到具有类型<int,矢量>的映射中<int>
- 在“std::map”中插入一个“int”值,该值应该存储“std::string”
- 在文件名中插入int变量
- 如何将元素插入 std::unordered_map<int, vector<Object*>>
- 插入 std::map<int, std::vector 的简短函数<int>>
- 为什么我的插入排序函数不会更改我从 int main 传递的数组
- 插入unordered_map<pair<int,int>, int> 抛出编译器错误
- 在 map<int 中插入,设置<int>>
- 将数据从两种不同的数据结构插入 std::map <std::string, int> mymap 并通过套接字发送
- 从文本文件中提取特定值(char & int)并插入到多个变量中C++
- 使用字符串流在文件名中插入int