C++ 将字符串划分为结构中的元素

C++ 将字符串划分为结构中的元素,c++,C++,我有一个文本文件,其中包含如下行: string, int string 我试着把每一行分成3个元素,发送给一个结构。 到目前为止,我的代码如下所示: #include "stdafx.h" #include <iostream> #include <string> #include <fstream> using namespace std; struct address { string street; int zip; string cit

我有一个文本文件,其中包含如下行:

string, int  string
我试着把每一行分成3个元素,发送给一个结构。 到目前为止,我的代码如下所示:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

struct address
{
 string street;
 int zip;
 string city;
};
istream & operator >>(istream & in, address & add)
{
 getline(in, add.street);
 getline(in, add.zip);
 getline(in, add.city);
}
#包括“stdafx.h”
#包括
#包括
#包括
使用名称空间std;
结构地址
{
弦街;;
int-zip;
字符串城市;
};
istream和operator>>(istream和in、地址和添加)
{
getline(内,添加街道);
getline(in,add.zip);
getline(in,add.city);
}

如果您有任何建议或帮助,我们将不胜感激。请提前感谢:D

因为字符串非常一致,这将是一个完美的通话位置。

字符串是否可以包含换行符?否则,取第一个分隔符设置为“
”、“
”的字符串。然后用cin提取int,用getline提取剩余字符串,并用
'\n'
提取,每一行都有相同的motiv。字符串(逗号)int(双空格)String对我来说太复杂了,朋友:)