Problem with main's arguments

This doesn't work from by shell.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char* argv[]) 
{
 fstream myfile;
 
 myfile.open(argv[1], ios::in);
 
 if(myfile)
 {
  cout << "File open!" <<endl;         
 }
 else
 {
  cout << "File do not exist!" <<endl;    
 }
  
 system("pause");
}


This works.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char* argv[]) 
{
 fstream myfile;
 
 myfile.open("file.txt", ios::in);
 
 if(myfile)
 {
  cout << "File open!" <<endl;         
 }
 else
 {
  cout << "File do not exist!" <<endl;    
 }
  
 system("pause");
}
Please don't spam the forum with multiple threads for the same question. People are already trying to help you with this in your other thread:

http://www.cplusplus.com/forum/beginner/122004/
Last edited on
Ah okok, then i erase first post since this is best described. =)
But you were already given helpful answers on that thread. Why would you want to abandon those and start over again? You're going to waste people's time because they'll try and explain things on this thread that were already explained on the other one.

Why are you trying to complicate the process of getting help?
Problem solved!!! Thanks to all! the problem has been resolved when I restart the pc ...
Topic archived. No new replies allowed.