C++ :: Allow User To Select Arbitrary File From Working Directory?

Apr 28, 2014

I know how to open a specific files by using

ifstream infile("something.txt");

but how do you let the user select an arbitrary file from the working directory?

View 12 Replies


ADVERTISEMENT

C :: Make A File In Directory That Cannot Be Deleted By User Out Of Program

Jul 4, 2013

I have two questions about C programming here :

1. I want to make a file in the program directory that can't be deleted by user out of the program make that file.for example if I make a file named "123.xyz" by the program named "text.exe" and then exit test.exe ,if I tried to delete the file 123.xyz I faced the error and I could not do it but by the test.exe program that make that file.

2. I heard about a function called "Parbegin()".any way i want to know is there any possible way to run two or more functions of a file.c together,like the parbegin function did an do in OS?

View 2 Replies View Related

C++ :: Program Prompts User To Select A Number Between 2 And 12 Twice?

Oct 8, 2014

Here is the whole code:

#include <iostream>
#include <ctime>
#include <cstdlib>
//This program prompts the user to select a number between 2 and 12
//computer throws two dices
//player win if selected number matches the sum of the two dices thrown by computer

[Code] .....

View 6 Replies View Related

C/C++ :: Let User Select Data Type From Menu

Nov 17, 2014

I have created a generic array-like template to create arrays of different types. Now I need to get user input from a menu about which type of array they are building. I tried having the user enter a number and using that number to pick a string from an array of constant strings. But pretty obviously, that threw a type conversion error. Is there a way to convert the literal string of a type into it's type or refer to a type directly.

Here is the code I need to fit a type into at runtime:

SimpleVector<TYPE> myVect = SimpleVector<TYPE>(dataSize);

View 5 Replies View Related

C++ :: Allow User To Select Repeatedly Operation To Be Performed From Displayed Menu Of Actions

May 1, 2013

Write a user-friendly C++ program that allows a user to select repeatedly an operation to be performed from a displayed menu of actions. The menu includes the following items:

1. Simple Statistics
2. Vector Addition
3. Dot Product
4. Exit

The menu actions are described by the following points:

Simple Statistics: This action includes finding the average, and standard deviation of a list of data items. The option should allow the user to specify the name of a file from which the data are read into an array. All the results of this option are displayed on the screen.

Vector Addition: This action allows the user to enter the name of a file from which two vectors, V1 and V2, of equal size N are read. Accordingly, the two vectors are added, and displayed along with the resultant vector on the screen. Your program should check that the two added vectors are of the same size. Otherwise, the program should display a message and allow the user to make another choice from the menu.

Dot Product: This action is similar to the Vector Addition in terms of input, output, and checking validity of the vector operands.

Exit: This action terminates the program.

Your program should include at least the following functions:

1. A function, called ReadVector(), which reads a vector of any size from a given file name, and returns the vector and its size to the caller. The function prototype is defined as follows:

void ReadVector(double V[], int &size, ifstream infile);

2. A function, called DisplayMenu(), which displays the menu and returns the user’s choice as an integer value between 1 and 4. The function prototype is defined as follows:
int DisplayMenu (void);

3. A function, called VectorAdd(), which performs the addition of two vectors, A and B, and returns the resultant vector, C. The function prototype is defined as follows:

void VectorAdd(const double A[], const double B[], double C[], int size);
The sum of two vectors, A = (a1, a2, …, an) and B = (b1, b2, …, bn) of size n, is defined as: C = A + B.
Where, C = (c1, c2, …, cn), and ci = ai + bi, for1 i n .

4. A function, called DotProduct(), which performs the dot product of two vectors, A and B, and returns the result. The function prototype is defined as follows:

void DotProduct(const double A[], const double B[], int size, double &result);
The dot-product of two vectors A = (a1, a2, …, an) and B = (b1, b2, …, bn) of size n is defined as
n n
n
i
i i b a ....... b a b a b a B . A  
1 1 2 2
1

5. A function, called Simple_Stat(), which finds the maximum, minimum, average, and standard deviation of a list of data items passed to it by a one-dimensional array. The function returns the average and standard deviation values. The function prototype is defined as follows:

void Simple_Stat(const double list[], int size, double &average, double
&std_dev);

View 1 Replies View Related

C :: How To Get User Home Directory

Oct 20, 2014

I want to obtain the user's home directory. I know it can be done with getenv("HOME"), but if I'll inspect the value of the enviroment variable HOME, it might work when I run it now, but it won't work on Windows, since windows uses HOMEPATH to save the user's home directory.

Is there a different, more cross-platform way to do it?

View 5 Replies View Related

C++ :: Get User Name And Surname In Active Directory?

Sep 11, 2013

I have a logined user and my running program as system process (not user process).

I want to get user name and surname from AD.

1. GetUserName() dont useful becouse it gets name for current process owner(for SYSTEM in my case).

2. There are userLogin, userName, userSurname and userDisplayedName in user properties of AD. Its possible to get userDisplayedName by NetUserGetInfo(), but
I want to know is it possible to get userName and userSurname?

View 1 Replies View Related

Visual C++ :: Accessing User Directory In Win 7 Pro?

Jul 12, 2013

I have been using the code below to extract the current user directory in order to read and write to certain files, presumeably independent of whether or not the user has administrative privileges. This has been necessitated in Win 7 because applications installed in the customary C:/Program Files(x86)/ are not allowed full access to files in the installed app root directory. This was working just fine until just this week when suddenly, for the first time, I found that the user directory retrieved was different when the app was run without administrative privileges in 'Start without debugging' configuration, both in Debug and Release configuration. Note that I have tested the identical app on Win2K and Vista and in neither case is it a problem on those OS machines. More mysterious is the fact that this ONLY happens on Win7 (VS2010 Ultimate) when run in the IDE. Run from the windows explorer double click, the app runs just fine in release and debug mode and monitoring the debug version using DbgView indicates that the expected 'Roaming' User directory is retrieved.

For example:

- without debugging (both Debug and Release configuration) the code below produces:

m_csUserDirectory =: C:UsersMPLIAMAppDataLocalPliaTechUeberKrypt

- with debugging (both Debug and Release configuration) the code below produces:

m_csUserDirectory =: C:UsersMPLIAMAppDataRoamingPliaTechUeberKrypt

Either this has been the situation from the outset and I just never noticed it (hard to imagine as I've been on this project for 6 months with 50+ builds), a recent Windows update has changed things, a bug, or I'm just plain stupid (not hard to imagine at all).

From a practical standpoint, if this is the way things are to be, my installer will need to install necessary files in both user directories and the app will need to access both depending upon user privileges.

Code:
/// This routine retrieves the process's environment block
/// using GetEnvironmentStrings, parses that block pointed to
/// by the generic international text pointer LPTCH, and returns
/// the requested string lpszVarStr as a string.
/// Note that the block lpvEnv environment variable substrings
/// are separated by NULL byte, and the block is terminated by a NULL byte.
/// The header files <windows.h>, <tchar.h>, <stdio.h>, <string>, and
/// <iostream> need to be included.

[code].....

View 5 Replies View Related

C++ :: How To Select A File

Dec 13, 2014

I am asking if there is a way to select a file

View 8 Replies View Related

C :: How To Select Words From A Text File

Oct 1, 2013

I've a text file with 9 words and each word is written in a line. for exemple this is the list :

APPLE
ORANGE
MOON
CAR
CANDY
...
END

I'm gonna choose the fourth line and select the word that is in this line and work on. I tried lot of way but no result.

View 7 Replies View Related

C++ :: Loop Not Working User Input?

Jan 20, 2013

Some of my loop is not working. How messed up is this code.. Commented non working code

// ADIT.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "windows.h"

[Code]....

View 3 Replies View Related

C++ :: Threads Never Execute In Arbitrary Order?

Jul 25, 2014

Code:

void Arrival_MainThread::Body () {
t1 = new boost::thread((Arrive_Fctor()), 2);
t2 = new boost::thread((Arrive_Fctor()), 10000);
t3 = new boost::thread((Arrive_Fctor()), 3000);

Code:
class Arrive_Fctor {
public:
void operator()(int mean) {
m_Arrivals = new Arrivals(mean);
m_Arrivals->Activate();
#ifndef NO_RESOURCE

[code].....

The order of arrivals always appear as 3,2,1 it can't be 1,2,3 or 3,1,2 or something like that?

The body method is called when m_Arrival->Activate() is executed, and it is running as an independent thread.

View 4 Replies View Related

C Sharp :: How To Select Specific Rows And Columns From A Text File

May 29, 2014

I want to select three columns from my text file i.e. Empl No, Start Date and Created Date. After selecting this, I want to insert the data into a database.

I have attached a copy of the text file.

I have the following code so far:
 
 if (File.Exists(filename))
                {  
                    string[] lines = File.ReadAllLines(filename);
                    for (int y = 0; y < lines.Length; y++) {    
                        Console.WriteLine(lines[y].ToString());  
                    }    

How do i select specific details for each employee

View 1 Replies View Related

C++ :: How To Save File Directory To Text File Using Ofstream

Jul 22, 2013

I'm having a little problem with std:fstream - in my program, the user selects the location of a file which I want to remember. So, I have something like this:

Code: std::string fileLocation;
//Code here creates an 'open file' dialog box which lets the user choose which file to open.
//The string 'fileLocation' now contains the path to the chosen file.
std::ofstream prefs("prefs.txt");
if (prefs.is_open())
{
prefs << fileLocation;
prefs.close();
}

This works fine if the file chosen is in the same directory as the program, however, if they try to choose a directory outside of where the program is kept, it saves the text file into that directory instead of the same one as the program. So, it looks like outputting a directory into an ofstream actually changes the location to which the file is saved.

Is there a way to save the file directory to a text file using ofstream and still have the text file save in the same directory as the program?

View 5 Replies View Related

C/C++ :: Read All Song Titles From A Text File - Randomly Select And Output?

Apr 19, 2015

So far I have managed to sort songs by their string length in main. The void function is there because i learned how to create it, but it's not being used because I dont know how to use it.

Expanding on main, how would I go about selecting a random song from the array?

#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
struct Song {
string song;

[code]....

View 2 Replies View Related

Visual C++ :: Arbitrary Sort Algorithm For Input (Bunch Of Rows)

Apr 5, 2013

C++ sort algorithm or library that can take input of a bunch of rows of data and then sort rows by an arbitrary defined order of one of the columns ... i.e., sort rows by value of the first column in this order (boba bobc bobe bobx) etc?

View 1 Replies View Related

C++ :: Program To Allow A User To Input A Number From Keyboard That Involves Loop Not Working Right?

Mar 30, 2014

I'm trying to write a C++ program that will allow a user to input a number from the keyboard. Then using a loop, that will perform 10 times, multiply the entered number by the loop counter. Print out the loop counter, the entered number and the product of the loop counter and the entered number. A one-time heading should be displayed before information is printed.

This kinda of what I have so far:

#include <iosteam>
using namespace std;
int main () {
Start
Declare: numScores, sum, score, avg, SENTINEL = 200
numScores = 0

[Code] ....

All the programs I have tried to make are not working?

View 4 Replies View Related

C :: Using Process ID As The Name Of File Directory

Jan 31, 2015

I need my Unix program to generate a directory with a format like this: "hinesro.<pid>". I have some code that mostly works, except for the directory ends up with a question mark on the end, like this: "hinesro.12345?". I need it to just display the directory without this question mark. Here is my code:

Code:

// Using headers sys/types.h, sys/stat.h, unistd.h, and stdio.h
int pid = getpid();
char prefix[] = "hinesro.";
char fileName[0];
sprintf(fileName, "%s%d
", prefix, pid);

[Code]...

View 13 Replies View Related

C++ :: Opening A File Within A Directory

Apr 26, 2013

I have problems opening a file within a directory.

#include <dirent.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

[Code] .....

Error Message:
$ ./dirsearch ~/Documents/College/textfiles/
[..]
[yomama.txt]
Error : Failed to open entry file - No such file or directory

Here are my current file permissions:
textfiles$ ls -l
total 8
-rw-rw-rw- 1 jav jav 7 Apr 26 13:14 moretext.txt
-rw-rw-rw- 1 jav jav 10 Apr 26 12:38 yomama.txt

View 6 Replies View Related

C/C++ :: Get File List From Directory By Name

Nov 19, 2012

I try to get file names listed by date or name in c. How can i do this.

There is a code: But this gives randomly file names.

DIR *dir;
struct dirent *ent;
    dir = opendir ("c:src");
if (dir != NULL) {  
  /* print all the files and directories within directory */
 
[Code] ....

View 2 Replies View Related

C++ :: Function To Build Multiplication Table Of Arbitrary Dimensions - Unexpected Output

Nov 8, 2013

So the latest challenge from jumping into c++ is as following.

Code:
Write a function that builds the multiplication table of arbitrary dimensions This chapter also talks a ton about 2d arrays.

So I've built my program thus far as this.

Code:
#include <iostream>
using namespace std;
int drawTable(int,int);
int main()

[Code] .....

So basically, the idea is that I can use the arrays dimensions as a placeholder, and just multiple them to get that specific spot, so table[0][0] = 0, [0][1] = 0 and so on. However the output actually seems to be randomly generated numbers so I'd like to ask, what am I doing wrong? Am I on the right track? Or have I missed the bus stop completely.

View 12 Replies View Related

C :: GCC Does Not Recognize Lib Location - No Such File Or Directory

Aug 19, 2013

I have my libraries in ../../lib location

and when i try to compile :

gcc -O9 -I ../../include/ -L ../../lib/ -o test test.c thr.o -lm -lthread

I get :

gcc: error: thr.o: No such file or directory

obviously the problem is the library path location but my obj is there

ls -al ../../lib/ | grep thr.o
-rw-rw-r-- 1 xxxxxx xxxxxx 23544 Aug 12 23:03 thr.o

????

View 2 Replies View Related

C++ :: Thread Library - No Such File Or Directory

Jul 25, 2014

When I write a code in c++ includes thread library it says "thread:no such file or directory". How can ı use thread library .

I think I should download boost or c++11 but I couldn't do it .

View 4 Replies View Related

C++ :: Trying To Substitute A Variable For File Directory

Jul 1, 2014

I am trying to substitute a variable for the file directory. Here is the error: error: no matching function for call to 'std::basic_ ofstream <char>:: basic_ ofstream(std::string&)'

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include <windows.h>
using namespace std;

[code]....

View 2 Replies View Related

C++ ::  Read Only The Oldest File From Directory

Jan 5, 2013

I'm quite new to C++ and got a problem of reading some files from a directory. All files is pure text, and I have no problem in reading these.

My problem is that I always have to read the oldest file without knowing the filename, and then move it to another directory and so on. Is it possible to use the timestamp instead of the filename to access the right file - read it and then move it to another directory?

View 3 Replies View Related

C++ :: Input File Directory From The Console?

Aug 19, 2014

Convert this code into one where you can input the file directory from the console?

#define WIN32_LEAN_AND_MEAN // prevent windows.h from including "kitchen sink"
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{LPCSTR Application = "C:Program FilesWindows Media Playerwmplayer.exe";
// Media file extension must be provided
// Paths are quoted

[Code] ....

This code works but the directory can only be changed from the code not the console.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved