|
Thanks I appreciate the help. I will try this and let you know.
Marsha
Marsha Eiter
|
|
|
|
|
char alpha[10] = "abcdefg";
string beta = "abcdefg";
alpha[1]= '\0'; gives the following result : alpha = a
beta[1]='\0'; gives the following result : beta = a cdefg
How can i use '\0' in strings as i use them in an array? I mean iwant that '\0' replace 'bcdefg' in string not just 'b'.
Thanks
|
|
|
|
|
#include<stdio.h>
void main()
{
char string1[10]="abcdef";
char string2[10]="abcdef";
string1[1]='\0';
string2[1]='\0';
printf("%s\n%s",string1,string2);
}
result:
a
a
----
i don't think it is wrong
ubri
|
|
|
|
|
Unfortunately, he is trying to modify a std::string and not a char array string.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks for the tip
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
Apparently, you are printing the result with the following: std::cout << beta << std::endl . If you print it with std::cout << beta.c_str() << std::endl , you get the desired print out. However, if you actually want to remove the characters following 'a' you can do this:
#include <iostream>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
std::string beta = "abcdefg";
beta.erase(beta.begin() + 1, beta.end());
std::cout << "Result #1: " << beta << std::endl;
std::cout << "Result #2: " << beta.c_str() << std::endl;
return 0;
}
Also, please post C++ questions in the C++ forum and not the C++/CLI forum.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi.
Thanks for the tip.
Pourang
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
You are little bit consfused with char[] and std :: string
Please Clear about that.
Best Regards,
Chetan Patel
|
|
|
|
|
Hi.
I got my answer but you're right. I'm reading the c++ Primer + and there are different chapters to cover String. I did not read the chapter which explains in details.
It sucks to be a beginner
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
Hi, I am using Visual Studio 2005 C++/CLI. I want to print via the print preview dialog. I set up the printPreviewDialog and created a document I could view with the printPreviewDialog. But when I used the print button to print what was being displayed only some of the document was printed. The bottom of the document was cut off. I thought that the print preview dialog showed what the printed output would look like (WYSIWYG) before you decided to print it. Isn't this the case?
Buck
|
|
|
|
|
Here is the code snippet of my application. background thread is a managed thread.
Code Snippet
public ref class Form1 : public System::Windows::Forms::Form
{
private:
Thread^ myThread; //Managed Thread Handle
IDiscovery* discObj // Pointer to unmanaged type
public :
static System::Void ThreadProc(System::Object^ pv)
{
System::IntPtr^ ptrDiscovery = cli::safe_cast<system::intptr^>(pv);
IDiscovery *discObj;
discObj = (IDiscovery *)ptrDiscovery->ToPointer();
//get the list from IDiscovery
discObj->discoverList(false);
}//END OF THREADPROC
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
System::IntPtr^ pV = gcnew System::IntPtr(static_cast<void*>(discObj));
myThread = gcnew Thread(gcnew ParameterizedThreadStart(Form1::ThreadProc));
myThread->Start(pV);
}//END OF FUNCTION
At times I am getting following exception:
An unhandled exception of type 'System.AccessViolationException'
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I am not sure whether this the right way to do it. Please suggest.
Thanks a lot,
Arti
|
|
|
|
|
art_ami wrote: 'System.AccessViolationException'
IDiscovery* discObj // Pointer to unmanaged type
is never initialized in the code you posted and could be the source of the error
|
|
|
|
|
It is initialized in the constructor. I just posted part of the Form1 class.
Also it works sometimes and sometimes I get this Exception
|
|
|
|
|
Hi, I am using Visual Studio 2005 C++/CLI. I am at the stage where I am rewriting the same application several different ways. This allows me to become more familiar and comfortable with the CLI syntax. In doing so there were a couple of Forms that had a lot of controls on them. Rather than re-create the Form and add all of the controls again I decided to used the Add->Existing Item command to add the Form information. Before adding I copied over the FormX.h, FormX.cpp and FormX.rex files into my current project directory, then I added them to the project. This works great except when I decided that I needed to modify the FormX[design]. I can't seem to get the FormX[design] window to open. Can someone tell me the correct procedure to add an existing Form from another project and then be able to modify the Form in the FormX[design] window?
Thanks
Buck
|
|
|
|
|
|
Sounds like you're asking a C++ question, which belongs in the Visual C++ forum. If you want to use .NET, this is the place to ask.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Armond,
Armond Sarkisian wrote: I tried to research the cmd.exe command but it doesn't start a whole new window. Anyone can help on this?
does 'start cmd' the trick for you?
(type 'help start' to see the options of the start command)
greetings,
ralf.
|
|
|
|
|
call dos commmand.
"start"
ShellExecute(NULL,NULL,"cmd /c start",....)
|
|
|
|
|
using namespace std;
void one () {
error C2871: 'std' : does not exist or is not a namespace
: error C2601: 'one' : local function definitions are illegal
|
|
|
|
|
Did you include iostream without .h?
|
|
|
|
|
This is the C++/CLI forum, try the visual C++ forum for standard C++ questons.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Can you help me.
Help to be going to create Virtual IP using "iphlp" libarary raise just there is example code using c++
wait for your advice.
thank you.
ps : thanks is add "iphlp" library fils(iphlp.h , iphlp.dll ...)
|
|
|
|
|
Same questions on different forums dear songjacky?
|
|
|
|
|
greetings and except my humbleness in asking you for your help, my general day to day doesn't involve a lot of actual programming, so when this came up i have been beating my head over it and finally succumbed to he kindness of strangers to help get it done. this is, in essence a C++ issue, as most of the string functions available to C++ are available to me, but it is built into an interface engine, so it is really base level (stuck to the basics, loops, ifs, etc). enough babble - here is what i need to do.
I am fed the following string:
720^JONES, A ANTHONY~^JONES, J JOHN~88^JOHSON, L
which is DRNUMBER^LASTNAME, MIDDLE INITIAL FIRSTNAME~NEXT DR~ and so on.
I am tasked with stripping out the occurances of dr.s without numbers, so any case without a number before the carat and then passing the string along with the others intact.
Any help would greatly appreciated!
Jason
|
|
|
|
|
You could use a strtok() function (or CStringT::Tokenize() if you're using CString)
to move from entry to entry ('~' is the delimeter).
For each string, compare the first character to '^' and/or check if it's numeric.
If it's a valid string, output it, else continue to next string.
Also, C++ questions that aren't related to Managed C++ should be posted on
the Visual C++/MFC board.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|