Jump to content

Writing a text file on cmd, C++ Program

Kagami Tsukino

I been searching on the web looking for ways on how to type a file location in the program. I at a lost how to do it. This is how it suppose to be. U2.png

Link to comment
Share on other sites

Link to post
Share on other sites

Easiest way would be to put your txt file in the same folder as the program you're running, then you can just type the name of the file with nothing else. 

 

Otherwise, in windows the paths are written like "c:\folder1\folder2\file.txt"

 

If none of those things (folder1, folder2, or file.txt) have spaces in them, then you can ignore the quotes, otherwise make sure the quotes are there. In fact, then won't hurt anything, so I'd just put them there anyway. 

 

Edit: Since I can't actually tell if you're on windows or other operating systems, bash (on mac and linux) write paths differently. They're written like "/Volumes/folder1/folder2/file.txt"

Link to comment
Share on other sites

Link to post
Share on other sites

you want to input a file thats user specified? if so im not 100% sure it can even be done, specefying the file in the code is fine but batch SUCKS ASS at usier input and wont really store text in variables IIRC 

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Which program?

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, corrado33 said:

Easiest way would be to put your txt file in the same folder as the program you're running, then you can just type the name of the file with nothing else. 

 

Otherwise, in windows the paths are written like "c:\folder1\folder2\file.txt"

 

If none of those things (folder1, folder2, or file.txt) have spaces in them, then you can ignore the quotes, otherwise make sure the quotes are there. In fact, then won't hurt anything, so I'd just put them there anyway. 

 

Edit: Since I can't actually tell if you're on windows or other operating systems, bash (on mac and linux) write paths differently. They're written like "/Volumes/folder1/folder2/file.txt"

 

6 minutes ago, Bananasplit_00 said:

you want to input a file thats user specified? if so im not 100% sure it can even be done, specefying the file in the code is fine but batch SUCKS ASS at usier input and wont really store text in variables IIRC 

I know that making a file and opening a file in C++ is possible, but is writing or opening a file on CMD even possible. This is for a project but now i just think the the professor just asking something nonsense.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Kagami Tsukino said:

 

I know that making a file and opening a file in C++ is possible, but is writing or opening a file on CMD even possible. This is for a project but now i just think the the professor just asking something nonsense.

you can read a file and you can select a file from a range of options using something like this:

 

@echo off
:start
echo what file?
echo 1: *file name here*
echo 2: *file name here*
echo 3: *file name here*
echo 4: *file name here*

set /p filenr= :

goto %filenr%

:1
print *path to first .txt*
pause
goto start

:2
print *path to secont .txt*
pause
goto start

:3
print *path to thire .txt*
pause
goto start

:4
print *path to fourth .txt*
pause
goto start

im a bit rusty with batch but that should work

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×