473,395 Members | 1,526 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,395 software developers and data experts.

String variables

I am new to oop c++ and I am trying to better educate myself on it. One issue that I have run into is how to store a string based variable.

Everything I have tried ends up with the errors below. Any information on this would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. DbConnect.h:7: error: ‘string’ does not name a type
  2. DbConnect.h:8: error: ‘string’ has not been declared
  3. DbConnect.h:9: error: ‘string’ does not name a type
  4. DbConnect.cpp:5: error: variable or field ‘db_set’ declared void
  5. DbConnect.cpp:5: error: ‘string’ was not declared in this scope
  6. DbConnect.cpp:9: error: ‘string’ does not name a type
  7.  
Here is my code.

DbConnect.h
Expand|Select|Wrap|Line Numbers
  1. #ifndef DBCONNECT_H_
  2. #define DBCONNECT_H_
  3.  
  4. class DbConnect
  5. {
  6. public:
  7.     string keep_value;                // private data value
  8.     void db_set(string db_value);    // public method to set value
  9.     string db_get(void);                    // public method to get value
  10. };
  11.  
  12. #endif /*DBCONNECT_H_*/
  13.  
DbConnect.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "DbConnect.h"
  2. #include <string>
  3.  
  4.  
  5. void DbConnect::db_set(string db_value){
  6.     keep_value = db_value;
  7. }
  8.  
  9. string DbConnect::db_get(void){
  10.     return (keep_value);
  11. }
  12.  
Dec 4 '08 #1
1 1606
mac11
256 100+
This is a namespacing issue. You need to either put "std::string" everywhere instead of just string or put "using namespace std" at the top of the file.

You also need to #include <string> in your .h file (any file that wants to use strings must #include <string> or include a file that does)
Dec 4 '08 #2

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

Similar topics

12
by: Eli Daniel | last post by:
Hi, I'm new to Python. Can you please tell me if the following is possible. My users are using other scripting launguage to write scripts. They are used to write somthing like (keeping it...
14
by: brad | last post by:
I've got a multithreaded application using std::string in Linux. Performance is not very good so I ran Quantify(tm) to look at what is happening. Most of the time my app was calling...
5
by: David Rasmussen | last post by:
If I have a string that contains the name of a function, can I call it? As in: def someFunction(): print "Hello" s = "someFunction" s() # I know this is wrong, but you get the idea... ...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
10
by: ksrajalakshmi | last post by:
Hai , in a textbox am having text as "(20/100)+pay1*pay2" .it's a formula. and stored in a particular variable. string strformula="(20/100)+pay1*pay2" ; i've to substitute the value of the...
5
by: Chris H | last post by:
Okay, I am trying to us a varialble with a list of number values as my data for an array, yet when I do this it doesnt return any values from the array, i was able to temporarily fix the proble by...
7
by: Andy C Matthews | last post by:
Hi there, I'm building an Access database and using VBA to generate Microsoft Word mailings for customers. It's all going fine so far. However, a variables named ParcelID, a ten-digit string such...
2
by: comp.lang.php | last post by:
I am trying to replace within the HTML string $html the following: With Where I'm replacing "action=move_image" with "action=<?= $_REQUEST ?>"
11
by: RipperT | last post by:
Don't know if this group covers web apps, but here goes. In VS 2005, I am trying to get variables to hold thier values during postback from the server. I convert a text box's user-keyed value to an...
1
by: kellysgirl | last post by:
Now what you are going to see posted here is both the set of instructions I was given..and the code I have written. The instructions I was given are as follows In this case, you will create...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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
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...

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.