|
-
February 26th, 2016, 05:57 PM
#11
Re: error C2106: '=' : left operand must be l-value
 Originally Posted by 2kaud
It is still good practice to deal with the case where it doesn't.
If you want it coded using a while loop then you are appending 1 to the string and then using SetAt to change this to the required char! Consider
Code:
#include <afx.h>
#include <iostream>
using namespace std;
int main()
{
CString one = " some text Q the rest of the text ";
CString two;
for (int x = 0; (x < one.GetLength()) && (one[x] != 'Q'); ++x)
two += one[x];
cout << two << endl;
}
So why are you setting two to the first part of one? If you want to extract part of string one then use .Find() and .Mid() (or .Right()). What part of the string do you actually want?
Finally I have used the solution you mention and it worked... the string I am working is a path string, something as: C:\Users\Public\Documents\some_folder\text.txt
so what I need the part "some_folder" extracted and been a CString
I have worked out how detect "\" before "some_folder" part, so what I needed was to copy everything before the next "\"...
All worked, I mean I was able to detect where to start copping and where to stop....
the actual copping the part of the CString one to CString two didn't work...
But with the help from this site I was able to do it in two methods:
1) using SetAt() function
2) char x=one[n];
two+=x;
both methods work, I kept the second one...
so, at the start I had two problems:
1) two[y]=one[x] // never works
2) CString two; // is empty string and it should not be empty
thanks for the help
regards
Val
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|