在线等 在线给分 字符串问题
1 想从文件中读入数据写入int数组中,例如文件是1,2,3,4,5
2 字符串“122 2 3 44 5” 怎么得出int数组 有没有简便的方法 例如JAVA的 SPLIT 函数
[解决办法]
// 1 想从文件中读入数据写入int数组中,例如文件是1,2,3,4,5
#include "iostream "
#include "fstream "
using namespace std;
int main()
{
vector <int> IntArray;
ifstream file( "test.txt ");
if (file.fail())
return 1;
while (!file.eof())
{
int n = 0;
file> > n;
IntArray.push_back(n);
}
file.close();
return 0;
}