对于我的任务,它说我要在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