473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using net use command in C++?

Hi everybody,

I am new to C++ and I would like to use this program to give the home
directory to each user.

My program is as below:

#include "iostream.h"

int main()

{
cout << "Home Directory for this user" << endl;
system("net use H: \\TEST\Home\%username%");
return 0;
}

I've got the message as below:
--------------------Configuration: HomeDirectory - Win32 Debug-----
Compiling...
HomeDirectory.cpp
D:\HomeDirectory\HomeDirectory.cpp(10) : error C2065: 'system' :
undeclared identifier
D:\HomeDirectory\HomeDirectory.cpp(10) : warning C4129: 'H' :
unrecognized character escape sequence
D:\HomeDirectory\HomeDirectory.cpp(10) : warning C4129: '%' :
unrecognized character escape sequence
Error executing cl.exe.

HomeDirectory.obj - 1 error(s), 2 warning(s)
Thank you so much for your assistance.

Jul 22 '05 #1
8 7591
chanchoth wrote:
Hi everybody,

I am new to C++ and I would like to use this program to give the home
directory to each user.

My program is as below:

#include "iostream.h"

int main()

{
cout << "Home Directory for this user" << endl;
system("net use H: \\TEST\Home\%username%");
The `/` character is somthing special in C/C++ characters
and strings. If you want a true `/` character then you
need to escape it with itself.

e.g.

"net use H:\\\\TEST\\Home\\%username%"
return 0;
}

I've got the message as below:
--------------------Configuration: HomeDirectory - Win32 Debug-----
Compiling...
HomeDirectory.cpp
D:\HomeDirectory\HomeDirectory.cpp(10) : error C2065: 'system' :
undeclared identifier
D:\HomeDirectory\HomeDirectory.cpp(10) : warning C4129: 'H' :
unrecognized character escape sequence
D:\HomeDirectory\HomeDirectory.cpp(10) : warning C4129: '%' :
unrecognized character escape sequence
Error executing cl.exe.

HomeDirectory.obj - 1 error(s), 2 warning(s)
Thank you so much for your assistance.

Jul 22 '05 #2
system() is defined in stdlib.h
#include <stdlib.h>

chanchoth <Ch************@gmail.com> wrote:
Hi everybody,

I am new to C++ and I would like to use this program to give the home
directory to each user.

My program is as below:

#include "iostream.h"

int main()

{
cout << "Home Directory for this user" << endl;
system("net use H: \\TEST\Home\%username%");
return 0;
}

I've got the message as below:
--------------------Configuration: HomeDirectory - Win32 Debug-----
Compiling...
HomeDirectory.cpp
D:\HomeDirectory\HomeDirectory.cpp(10) : error C2065: 'system' :
undeclared identifier
D:\HomeDirectory\HomeDirectory.cpp(10) : warning C4129: 'H' :
unrecognized character escape sequence
D:\HomeDirectory\HomeDirectory.cpp(10) : warning C4129: '%' :
unrecognized character escape sequence
Error executing cl.exe.

HomeDirectory.obj - 1 error(s), 2 warning(s)
Thank you so much for your assistance.

Jul 22 '05 #3
chanchoth wrote:
Hi everybody,

I am new to C++ and I would like to use this program to give the home
directory to each user.

My program is as below:


// For std::cout
#include <iostream>

// For std::system
#include <cstdlib>

// For std::endl
#include <ostream>

int main()
{
using namespace std;

cout << "Home Directory for this user" << endl;

// I do not know "net use", however I think it should be:
system("net use H:\\TEST\\Home\\%username%");

return 0;
}


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #4
[ ... ]
system("net use H: \\TEST\Home\%username%");


The answer has been hinted at, but not yet given correctly. You need
two backslashes in your source code to produce a single backslash.

system("net use H: \\\\TEST\\Home\\%username%");

P.S. You might want to ask on comp.os.ms-windows.programmer.win32 about
WNetAddConnection{2|3} to do the job without an external program.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 22 '05 #5
"Ioannis Vranos" <iv*@remove.this.grad.com> wrote in message
news:1105949465.709892@athnrd02...
chanchoth wrote:
Hi everybody,

I am new to C++ and I would like to use this program to give the home
directory to each user.

My program is as below:


// For std::cout
#include <iostream>

// For std::system
#include <cstdlib>

// For std::endl
#include <ostream>


<snip>

Including <ostream> after including <iostream> is unnecessarily redundant,
don't you think?
Jul 22 '05 #6
Richards Noah (IFR LIT MET) wrote:
Including <ostream> after including <iostream> is unnecessarily redundant,
don't you think?

http://groups.google.com/groups?q=%3...rio.net&rnum=2

http://groups.google.com/groups?hl=e...e11.lga#link17


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #7

"Richards Noah (IFR LIT MET)" <No***********@infineon.com> wrote in message
news:cs**********@athen03.muc.infineon.com...
"Ioannis Vranos" <iv*@remove.this.grad.com> wrote in message
news:1105949465.709892@athnrd02...
chanchoth wrote:
Hi everybody,

I am new to C++ and I would like to use this program to give the home
directory to each user.

My program is as below:


// For std::cout
#include <iostream>

// For std::system
#include <cstdlib>

// For std::endl
#include <ostream>


<snip>

Including <ostream> after including <iostream> is unnecessarily redundant,
don't you think?


No. 'endl' is declared by <ostream>, not <iostream>.
Many implementations' <iostream> header does #include
<ostream>, but there's no requirement that it does.
I seem to recall a recent lengthy debate about this,
here, or at alt.comp.lang.learn.c-c++.

If you need to refer to a standard library name, #include
the header that declares it. Don't depend upon possible
(or common) implementation details.

-Mike
Jul 22 '05 #8
Ioannis Vranos wrote:
Richards Noah (IFR LIT MET) wrote:
Including <ostream> after including <iostream> is unnecessarily
redundant,
don't you think?


http://groups.google.com/groups?q=%3...rio.net&rnum=2
http://groups.google.com/groups?hl=e...e11.lga#link17


http://groups-beta.google.com/group/...8b7f3087e6a081

Including a little debate going on right now ...
Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
1
by: Junior | last post by:
I keep receiving this "The type or namespace name 'CASsEventHandler' could not be found (are you missing a using directive or an assembly reference?)" message in two particular lines, and I've...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
4
by: Tim Golden | last post by:
Tim Golden enlightened us with: > > Well, I'm with you. I'm sure a lot of people will chime in to point > > out just how flexible and useful and productive Linux is as a > > workstation, but every...
8
by: Andrew Robinson | last post by:
Are these two equivalent? Is one better than the other? I tend to go with #1 but started wondering.... Thanks, 1: using (SqlConnection cn = new SqlConnection(DataConnection)) using...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
1
by: Barry L. Camp | last post by:
Hi all, Wondering if someone can help with a nagging problem I am having using a GridView and an ObjectDataSource. I have a simple situation where I am trying to delete a row from a table, but...
4
by: ohaqqi | last post by:
Hi everybody. I haven't programmed anything in about 8 years, I've read up a little bit on C and need to write a shell in C. I want to use strtok() to take an input from a user and parse it into the...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.