0,1,2,3,…

IN:={Ø,{Ø},{Ø,{Ø}},{Ø,{Ø},{Ø,{Ø}}},…}

ios January 11, 2012

Filed under: Uncategorized — abi007 @ 5:29 pm

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
typedef struct data{
int a;
int b;
};

void fkt(string str, int s, vector<data> vektor){
stringstream ss(str);
int s1;
ss>>s1;
vektor[s].a=s1;
}
void fktb(string str, int s, vector<data> vektor){
stringstream ss(str);
int s1;
ss>>s1;
vektor[s].b=s1;
}
void fkt3(int s, vector<string> vektor2, string str){
char *cstr, *p;
cstr=new char [str.size()+1];
strcpy(cstr, str.c_str());
p=strtok(cstr, ” \n”);
while (p!=NULL)
{
vektor2[s]=p;
p=strtok(NULL,” \n”);

cout<<vektor2[s]<<”;”;
}
}
int main () {
vector<data> vektor(10);
vector<string> vektor2(10);
string line;
ifstream myfile (“c:\\text.txt”);
int s=0;
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
string str1;
str1=line;

size_t pos;
pos = str1.find(” “)+1;

fkt(str1.substr(0,pos-1),s,vektor);

stringstream ss(str1.substr(0,pos-1));
int s1;
ss>>s1;
vektor[s].a=s1;

string str2;
str2=str1.substr(pos);

stringstream st(str2);
int s2;
st>>s2;
vektor[s].b=s2;

cout<<”vektor:”<<vektor[s].a<<” “<<vektor[s].b<<endl;
s++;

fkt3(s,vektor2,line);
}
myfile.close();
}

else cout << “Unable to open file”;
cin.get();
return 0;
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.