4 Replies - 5059 Views - Last Post: 07 November 2010 - 05:09 AM Rate Topic: -----

#1 deletrius  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-November 10

How to read text file name from command line argument in visual c++ ex

Posted 06 November 2010 - 09:54 PM

Hi experts, I was wondering how would I be able to set the command line arguments in visual c++ 2010 express so that my c++ code can use that argument. For example, in cygwin, I would type this to run the c++ program:

./index filename.txt


and somewhere in my code, i have this line:

int main(int argc, char *argv[])
{
  string bookName = argv[1];
  string outputName = argv[2];
}



an example would be great and thanks so much

Is This A Good Question/Topic? 0
  • +

Replies To: How to read text file name from command line argument in visual c++ ex

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: How to read text file name from command line argument in visual c++ ex

Posted 06 November 2010 - 10:07 PM

Wrap your snippet in enough of a main() so you can try compiling it.
Add a line that prints the value in argv[1] to the screen.
Does your code compile?
If not what errors do you get?
Was This Post Helpful? 0
  • +
  • -

#3 deletrius  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-November 10

Re: How to read text file name from command line argument in visual c++ ex

Posted 06 November 2010 - 10:54 PM

Oh, thanks for the printing value of argv tip, i figured it out.
It's right click on your project name -> properties -> debugging -> command arguments
and i placed my text file in: C:\Users\<username>\Documents\Visual Studio 2010\Projects\<projectName>
Was This Post Helpful? 0
  • +
  • -

#4 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: How to read text file name from command line argument in visual c++ ex

Posted 06 November 2010 - 10:58 PM

That's not even close to what I was thinking you might do.
I was thinking of a cout statement in some code inside a main() function.

But what matters is does it work for you?

Is your problem fixed?
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,215
  • Joined: 23-August 08

Re: How to read text file name from command line argument in visual c++ ex

Posted 07 November 2010 - 05:09 AM

Oh, this is an IDE question, not a code question!

Project Menu->Properties->Configuration Properties->Debugging->Command Arguments
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1