小编jko*_*jko的帖子

理解:从int地址转换为char数组

这条线具体是做什么的?

(char*) (&input)

我知道它将 int(input) 转换为 char 数组..还是我错了?你能指导我它是如何计算的吗?

更新:我想我现在明白了一点,然后我根据你的评论创建了 C++ 代码

#include <cstdlib>
#include <iostream>

using namespace std;
int main(){
 int input = 123456;
 int *p = &input;

 char *cp = (char*)p; 

for(int counter = 0;counter <sizeof(input); counter++){        
        cout << *(cp+counter) << endl;
        }


 system("pause");
 return 0;
}
Run Code Online (Sandbox Code Playgroud)

但我认为我的代码是错误的。因为它只显示“@”,大“r”?,以及诸如十字符号之类的东西......

c++

2
推荐指数
1
解决办法
2810
查看次数

c ++:赋值中的非Ivalue

嗨,我想制作一个外部单链表.我有一个问题"赋值中的非Ivalue"及其出现在行"this = currP-> next"我试图使它成为currP.next但它也产生错误

#include <cstdlib>
using namespace std;


struct node{
       int data;
       node *next;

       node(int i){
                data = i;
                next = NULL;
                }

       void insert(int position, node &n){
            node *currP = this;
            node *prevP= NULL;      
            for(int counter = 0; counter>=position;counter++, prevP = currP, currP = currP->next){
                    if(counter==position)
                    {
                    n.next  = currP->next;
                    currP->next = &n; 
                                         }                     
                    }

            }

       void add(node &n){
       next = &n;          
                 }
       void deleteNode(int i){
            node *currP = this;
            node *prevP = NULL;

            while(currP!= NULL){
               if(currP->data == …
Run Code Online (Sandbox Code Playgroud)

c++ pointers

1
推荐指数
1
解决办法
318
查看次数

从List*到int的转换无效

我创建了一个链表:struct Node和List Class,我在我的main方法外面使用它,

#include "Lists.cpp"
#include <cstdlib>
using namespace std;

int main(){


    Lists l = new Lists(1);

    l.add(2);
    l.add(3);
    l.add(4);
    l.add(5);



    system("pause");
    return 0;
        }
Run Code Online (Sandbox Code Playgroud)

但它会产生一个错误,表示"从List*到int的转换无效".我使用外面的课吗?我有点困惑,我将如何解决这个问题.

#include <cstdlib>
#include <iostream>

using namespace std;

struct Node{
       int data;
       Node *next;       
       Node(int i){
                data = i;
                next = NULL;
                }

       };

class List{
      Node *head;



      public:
      List(int i){
               head = new Node(i);
      }

      void addToHead(int i){
          Node *temp = new Node(i);
          temp->next = head;
          head = temp;
           }

      void add(int i){
                Node …
Run Code Online (Sandbox Code Playgroud)

c++ class

0
推荐指数
1
解决办法
4732
查看次数

标签 统计

c++ ×3

class ×1

pointers ×1