[問題] structure一問
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
typedef struct node
{
string name;
int number;
struct node* prev;
struct node* link;
} NODE;
int main()
{
string geTmp;
string strTmp;
string inTmp;
NODE* list;
string filenameR = "phone.txt";
ifstream inFile;
inFile.open(filenameR.c_str());
while( getline(inFile, geTmp) )
{
list = (NODE*)malloc(sizeof(NODE));
stringstream token(geTmp);
while(1)
{
token>>strTmp;
if(token.fail())
{
break;
}
list->name = strTmp;
token>>inTmp;
list->number = atoi( inTmp.c_str() );
cout<<list->number<<endl;
cout<<strTmp<<endl;
}
}
return 0;
}
若將黃色的部份蓋掉 程式就不會出問題
覺得蠻怪的 把讀到東西存成string
然後assign給structure裡面的string
data type一樣 卻會當掉....不知道原因為何ˊ ˋ"
請問有人能幫忙解惑嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.243.94
推
05/11 20:44, , 1F
05/11 20:44, 1F
→
05/11 21:00, , 2F
05/11 21:00, 2F
推
05/11 22:07, , 3F
05/11 22:07, 3F
推
05/11 22:15, , 4F
05/11 22:15, 4F
→
05/11 22:17, , 5F
05/11 22:17, 5F
→
05/11 22:18, , 6F
05/11 22:18, 6F
→
05/11 22:18, , 7F
05/11 22:18, 7F
→
05/12 11:15, , 8F
05/12 11:15, 8F
→
05/12 11:15, , 9F
05/12 11:15, 9F
→
05/12 13:27, , 10F
05/12 13:27, 10F
推
05/12 13:37, , 11F
05/12 13:37, 11F
→
05/12 21:28, , 12F
05/12 21:28, 12F
→
05/12 21:42, , 13F
05/12 21:42, 13F
→
05/12 21:55, , 14F
05/12 21:55, 14F
→
05/12 21:56, , 15F
05/12 21:56, 15F
→
05/12 21:57, , 16F
05/12 21:57, 16F
→
05/12 21:59, , 17F
05/12 21:59, 17F
→
05/12 21:59, , 18F
05/12 21:59, 18F
→
05/12 22:01, , 19F
05/12 22:01, 19F