argv [1]在对象的默认构造函数中?

时间:2016-10-28 01:17:46

标签: c++ visual-studio-2015

我正在尝试制作一个Windows窗体c ++程序,一切正常,但我无法弄清楚如何在对象的默认构造函数中使用命令行参数

#pragma once
#include<iostream>
#include<string>
#include<fstream>
#include"Quotes.h"
#include<stdlib.h>
Quotes::Quotes()
{
    std::ifstream quoteList;
    std::string line, theme, author, birth, death;

    quoteList.open("quotes.txt");
    if (!quoteList.is_open()) {
        std::cout << "FILE NOT FOUND. QUITTING PROGRAM." << std::endl;
        exit(EXIT_SUCCESS);
    }

    for (int i = 0; !quoteList.eof() && i < 300; i++) //as _Quotes is an array of 300, limits loop to 300
    {
        getline(quoteList, line); //read in the quote
        getline(quoteList, theme); //read in the theme
        getline(quoteList, author, '('); //read in the author up to the opening parantheses for the year
        author[author.length() - 1] = ','; //replaces space after author's name with a comma
        getline(quoteList, birth, ' '); //read in the birth year up to the immediately following space
        quoteList.ignore(); //to skip the '-'
        quoteList.ignore(); //to skip the space after '-'
        getline(quoteList, death, ')'); //read in death year up to the closing parantheses
        quoteList.ignore(); // to skip the \n character
        Author tempAuthor(author, birth, death); //creates a variable author with appropriate information to be used for copying
        Quote tempQuote(line, theme, tempAuthor); //initialize a new instance of Quote with the info we need, then....
        _Quotes[i].copy(tempQuote, tempAuthor); //copy it over to _Quotes[i] and now it has the proper values
    }
    quoteList.close();
}

很抱歉,如果该代码不必要,这是我的第一个问题,但如何将"quotes.txt"替换为argv[1]?我尝试的任何事情都是

0 个答案:

没有答案