내 프로그램에 대한 솔루션을 빌드 할 때 '문자열': 선언되지 않은 식별자 오류가 발생합니다. 함수 선언에 문자열 형식을 선언하는 것과 관련이 있다고 생각합니다. 프로그램의 나머지 코드 여기C2061 'string': 선언되지 않은 식별자
#include <iostream>
#include <string>
#include "stdafx.h"
using namespace std;
void addNode(struct Node *head, string text);
struct Node {
string info;
string out;
Node* next;
};
입니다 :
int main()
{
const int width = 2; // the number of cells on the X axis
const int height = 2; // the number of cells on the Y axis
string grid[height];
struct Node *list = new Node;
struct Node *listcpy;
grid[0] = "00";
grid[0] = "0.";
//----------------------------------------------------------------------------------
for (int i = 0; i < height; i++) {
addNode(list, grid[i]);
}
listcpy = list; //holds pointer to beggining of list
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if (list->info[j] == '0') //if current cell is a node
{
list->out.append(to_string(i) + " " + to_string(j) + " "); //append nodes coordinate
if (j < width - 1) //if right cell exists
{
if (list->info[j + 1] == '0') { //if there is node to the right
list->out.append(to_string(i) + " " + to_string(j + 1) + " ");
}
else {
list->out.append("-1 -1 ");
}
if (i < height - 1) //if bottom cell exists
{
if (list->next->info[j] == '0') { //if there is node at the bottom
list->out.append(to_string(i + 1) + " " + to_string(j) + " ");
}
else {
list->out.append("-1 -1 ");
}
}
}
list = list->next;
}
while (listcpy != NULL)
{
if (listcpy->out != "")
{
cout << listcpy->out << endl;
}
listcpy = listcpy->next;
}
}
}
}
// apending
void addNode(struct Node *head, string text)
{
Node *newNode = new Node;
newNode->info = text;
newNode->next = NULL;
newNode->out = "";
Node *cur = head;
while (cur) {
if (cur->next == NULL) {
cur->next = newNode;
return;
}
cur = cur->next;
}
}
사람이 오류를 해결하는 방법을 알고 있나요
을 오류 먼저 추가 노드에 대한 함수 서명에 나타납니다?
'#include "stdafx.h"'를 제거하십시오. –
'struct node * list''struct' 선언문은 새로운 타입 이름을 선언하기 때문에 C++에서는 필요 없습니다. – crashmstr
Visual Studio에서 작업하고 있고 미리 컴파일 된 헤더가있는 경우 '#include "stdafx.h"'* *를 첫 번째 포함해야합니다. – crashmstr