1

So, I am using https://stackoverflow.com/a/298713/1472828 to put an argument "hands.txt" (my agrv[1], which is a file I wanna open) in my command arguments. I have tried both hands.txt and "hands.txt", neither of them worked.

int FileParsing(vector<Card> & v, char * FileName) {
    ifstream ifs;
    ifs.open(FileName);
    if (!ifs.is_open()){
        cout << "file cannot be opened." << endl;
    } else {

So I use debugger to step through my main:

int main(int argc, char * argv[]){
    if (argc !=2 ){
        //ErrorMessage();
    } else {
         ...

Debugger tells me that my argc is 2, which is right, but how come every time the debugger just goes to

cout << "file cannot be opened." << endl;

which means the argument just fails at reading it

ifstream ifs;
ifs.open(FileName);

Is there something I missed or I passed the argument in a wrong way?

p.s. The text file was read perfectly from cmd, so it's not the problem of code.

4

1 回答 1

4

从@WhozCraig 得到这个想法,在 cmd 中运行程序时,文本文件放在调试目录下。但是如果使用调试器运行它,则必须将文本文件与其他 cpp 和 h 文件放在同一目录中。

于 2013-03-10T16:44:07.030 回答