simple string problem

This is a discussion on simple string problem within the C++ Programming forums, part of the General Programming Boards category; Ok I am new to C++ and I have this problem: Code: details = dateStr + "," + staffid + ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    4

    simple string problem

    Ok I am new to C++ and I have this problem:

    Code:
    details = dateStr + "," + staffid + "," + totalitems + "," + totalprice + "," + payment_method + "," + amount_paid + "\n";
    error C2110: cannot add two pointers

    Any help on this? The data strucutres are:

    string details;
    char dateStr[9];
    int staffid;
    int totalitems = 0;
    double totalprice = 0;
    int payment_method;
    double amount_paid = 0;

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    Post a bit more of the code. When you say data structrues, I think of this:

    Code:
    struct Fruit
    {
       string lemon;
       int lemonAmount;
    };
    You have a list of varible declarations
    I'm just trying to be a better person - My Name Is Earl

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    try this
    Code:
    #include <string>
    #include <sstream>
    
    int main()
    {
    	std::string details;
    	std::stringstream stuff;
    	char dateStr[9] = "Hello";
    	int staffid = 0;
    	int totalitems = 1;
    	double totalprice = 0.5;
    	int payment_method;
    	double amount_paid = 0;
    	stuff << dateStr << "," << staffid << "," << totalitems << "," << totalprice << ",";
    	details = stuff.str();
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Posts
    4
    Thanks a lot, that really helps

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  2. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 04:58 PM
  3. C/C++ String Problem.
    By Jaken Veina in forum C++ Programming
    Replies: 7
    Last Post: 07-09-2005, 11:11 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21