[ create a new paste ] login | about

Link: http://codepad.org/I6sSx1GH    [ raw code | output | fork ]

C++, pasted on Feb 14:
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <iostream>
using namespace std;

int main(){
    //это эммуляция файла
    string data = "1 2 3\n"
                  "4 5 6\n"
                  "7 8 9";
    string line;
    float fValue = 0;
    vector< vector< float > > matrix;
    stringstream ifs(data);//заменить на fstream.open
    while( ifs>>line )
    {
        vector< float > fLine;
        stringstream ss(line);
        while( ss>>fValue )
            fLine.push_back(fValue);
        matrix.push_back(fLine);
    }
    for( size_t i = 0; i < matrix.size(); i++ )
    {
        for( size_t j = 0; j < matrix[i].size(); j++ )
            cout<<matrix[i][j]<<" ";
        cout<<endl;
    }
    return 0;
}


Output:
1
2
3
4
5
6
7
8
9
1 
2 
3 
4 
5 
6 
7 
8 
9 


Create a new paste based on this one


Comments: