對於我的任務,它說我要在main.cpp中使用命令行參數./a.out user1.txt(文本文件名可以更改)。C++的命令行參數?
我有我的main.cpp
int main(int argc, char* argv[]){
string name;
name = argv[1];
}
以下,但不知道我怎樣才能名進入BBoard CPP我BBoard設置功能
#include "BBoard.h"
#include <fstream>
#include <algorithm>
using namespace std;
User user_l;
BBoard::BBoard(){
title = "Default BBoard";
vector<User> user_list;
User current_user;
vector<Message> message_list;
}
BBoard::BBoard(const string &ttl){
title = ttl;
}
void BBoard::setup(const string &input_file){
ifstream fin;;
fin.open(input_file);
while(!fin.eof()){
user_list.push_back(user_l);
}
}
與BBoard頭這裏
#ifndef BBOARD_H
#define BBOARD_H
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class User
{
public:
User() { }
User(const std::string& _name, const std::string& _pass)
: name(_name), pass(_pass)
{ }
friend bool operator==(const User& lhs, const User& rhs)
{
return (lhs.name == rhs.name) &&
(lhs.pass == rhs.pass);
}
private:
std::string name;
std::string pass;
};
class Message{
};
class BBoard{
private:
string title;
vector<User> user_list;
User current_user;
vector<Message> message_list;
public:
BBoard();
BBoard(const string &ttl);
};
#endif
編輯:如何使用主cpp中的對象將名稱發送到BBoard函數?當我嘗試將主要cpp包含到我的主板cpp中時,出現錯誤。
另一個祕訣:從不包括源文件;即不會執行'#include「main.cpp」'或類似的操作。 – noobProgrammer