| | |
MyString Woes
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
I was absent for the discussion and lab due to illness and I am at a total loss as to how to do this assignment.
Implement the my_string class in header file my_string.h, so that the test code given below reports SUCCESS.
I cannot get the program to get past
nor can I get
What am I missing here?
Implement the my_string class in header file my_string.h, so that the test code given below reports SUCCESS.
C++ Syntax (Toggle Plain Text)
// test_my_string.cpp #include <iostream> #include <string> #include <cassert> #include "my_string.h" using namespace std; //#define STRING string #define STRING my_string int main() { STRING s1; // s1 == "" assert(s1.length() == 0); STRING s2("hi"); // s2 == "hi" assert(s2.length() == 2); STRING s3(s2); // s3 == "hi" assert(s3.length() == 2); assert(s3[0] == 'h'); assert(s3[1] == 'i'); s1 = s2; // s1 == "hi" s3 = "bye"; // s3 == "bye" assert(s3.length() == 3); assert(s3[0] == 'b'); assert(s3[1] == 'y'); assert(s3[2] == 'e'); s1 += "re"; // s1 == "hire" assert(s1.length() == 4); assert(s1[0] == 'h'); assert(s1[1] == 'i'); assert(s1[2] == 'r'); assert(s1[3] == 'e'); cout << "SUCCESS" << endl;
I cannot get the program to get past
assert(s3[0] == 'h'); nor can I get
cout << s3[0]; to work.What am I missing here?
Last edited by FC Jamison; Jan 16th, 2007 at 1:54 am.
Nevermind...
I got it to work using
I got it to work using
C++ Syntax (Toggle Plain Text)
char &operator[](unsigned int index) { return str[index]; }
![]() |
Similar Threads
- QBASIC under Windows XP (Visual Basic 4 / 5 / 6)
- LCD vs CRT (Monitors, Displays and Video Cards)
- Web design table woes (HTML and CSS)
- Jscript Replace Function (ASP)
- Google PR (Search Engine Optimization)
- hm.. wiered.. (C)
- struct error (!?) (C)
Other Threads in the C++ Forum
- Previous Thread: Setprecision help please
- Next Thread: Adding Random Numbers help
Views: 1039 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





