473,506 Members | 16,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I convert string variable to char*??

3 New Member
hey,
I am pretty new to c++ programming and I am supposed to use system(const char*). But I have a string variable as the argument. Can any1 please help me how to use this string variable as argument to system()? thanks in advance.
-kaushik
Jul 3 '08 #1
3 3639
kaushiknanda
3 New Member
hey,
I am pretty new to c++ programming and I am supposed to use system(const char*). But I have a string variable as the argument. Can any1 please help me how to use this string variable as argument to system()? thanks in advance.
-kaushik

i m getting the following error:

cannot convert 'std::string' to 'constant char*' for argument '1' to 'int system(constant char*)'
Jul 3 '08 #2
scruggsy
147 New Member
i m getting the following error:

cannot convert 'std::string' to 'constant char*' for argument '1' to 'int system(constant char*)'
std::string has a c_str() function that returns a const char*, i.e.:
Expand|Select|Wrap|Line Numbers
  1. std::string stringThing("A C++ string");
  2. const char* cStyleString = stringThing.c_str();
Quick google-search or peek at the index of a C++ reference book should get you acquainted with other useful std::string methods.
Jul 3 '08 #3
kaushiknanda
3 New Member
std::string has a c_str() function that returns a const char*, i.e.:
Expand|Select|Wrap|Line Numbers
  1. std::string stringThing("A C++ string");
  2. const char* cStyleString = stringThing.c_str();
Quick google-search or peek at the index of a C++ reference book should get you acquainted with other useful std::string methods.
thanks a lot ...it worked
Jul 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
6144
by: IamZadok | last post by:
Hi I was wondering if anyone knew how to convert a string or an integer into a Static Char. Thx
7
3149
by: Bernardo | last post by:
Hi There is any easy way to convert a 1Char string to a char variable string str="A" char ch=str.. Thanks for your help
3
5618
by: keith | last post by:
In managed C++, there is variable String *s. The variable got value from a C# assembly. Then I need to convert it into char *c in order to call an external function in a dll that accepts parameter...
14
1463
by: Drew | last post by:
Hi All: I know I am missing something easy but I can't find the problem! I have a program which reads an integer as input. The output of the program should be the sum of all the digits in the...
3
3642
by: David | last post by:
Hi, how to convert a char array(byte) to a string variable? byte buffer; string strTest; /*the blow codes all get type of 'buffer': System.Byte! strTest = buffer.ToString() strTest =...
3
9174
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string from a file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
5
6017
by: sjsn | last post by:
Basic C++, just started this course in school... So I'm very limited. What I'm at doing is, below I have a variable named inputTemp, which is the product of a char, F = Fahrenheit, C = Celsius...
8
8388
by: Polaris431 | last post by:
I have a buffer that holds characters. Four characters in a row represent an unsigned 32 bit value. I want to convert these characters to a 32 bit value. For example: char buffer; buffer =...
2
2438
by: sangyarts | last post by:
problem in C++ -variable of type std::string called str egl std:string str; // declaration str+ ""; // initialized to this.........nothing.
14
13427
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. ...
0
7218
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,...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.