-1

Here is my vector from a dictionary file :

//
//
//
//
#include <iostream>
#include <string>
#include <math.h>
#include <fstream>
#include <vector>
#include <regex>

using namespace std;

/**
 * Read file function
 * @params path : path of the file
 * @params skip_line : num of line to skip from begining
 * @params limit_line
 * @params parse_data : put data from file to array
 * @return : execution time
 */
long read_data(string path, int skip_line, int limit_line, vector<string> &parse_data) {
    long time = clock();
    ifstream stream(path);
    if (!stream) {
        cerr << "File : " + path + " not found." << endl;
        return -1;
    }
    string line; int count = 0;
    while (getline(stream, line)) {
        if (count<skip_line) {
            count++;
            continue;
        }
        if (count >= limit_line && limit_line > 0) {
            break;
        }
        if (line.empty()) {
            continue;
        }
        count++;
        try{
            string delimiter_keyword = "#";
            string delimiter_translate = "*";
            string pre_translate = line.substr(0, line.find(delimiter_translate));
            string translate = line.substr(line.find(delimiter_translate)+1);

            string key_word = pre_translate.substr(0, pre_translate.find(delimiter_keyword));
            string pronounce_word = pre_translate.substr(pre_translate.find(delimiter_keyword));

//            cout << translate << endl;
//            cout << pronounce_word << endl;
            parse_data.push_back(key_word);
        } catch(exception ex) {
            // parse exception
        }
    }
    stream.close();
    time = (clock() - time)/ double(CLOCKS_PER_SEC) * 1000;
    return time;
}

long heap_sort(){
    long time = clock();
    /**
     * Help code here.
     */
    time = (clock() - time)/ double(CLOCKS_PER_SEC) * 1000;
    return time;
}

long quick_sort(){
    long time = clock();
    /**
     * Help code here.
     */
    time = (clock() - time)/ double(CLOCKS_PER_SEC) * 1000;
    return time;
}


int main() {
    int limit_line = 0;
    vector<string> dictionary_data;
    int exec_time = read_data(
            "D:\Nam 2\Cau truc du lieu va giai thuat\av.dd",
            3, limit_line, dictionary_data
    );
    cout << "Total time : " << exec_time << " ms" << endl;


    for (string line : dictionary_data) {
        cout << line << endl;
    }
}

How can i convert this vector to a string[n] so i can put my sort algothrims into it ? Thanks

Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

0

How can i convert this vector to a string[n]

A vector can not be converted to an array.

What you can do, is copy the contents of a vector to an array. But you don't want to do that, because you usually cannot know at compile time, how big the vector is going to be.

so i can put my sort algothrims into it ?

You don't need to "convert" a vector to an array in order to do that. Use the array contained within the vector as it is.

eerorika
  • 232,697
  • 12
  • 197
  • 326