AQssign same value to int & string?

This is a discussion on AQssign same value to int & string? within the C++ Programming forums, part of the General Programming Boards category; I need to assign the same value to an int & string but don't want to have the user answer ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    2

    AQssign same value to int & string?

    I need to assign the same value to an int & string but don't want to have the user answer the same question ( see below). When the user enters the "sequence starting number" i would like that value assigned to swill(string) and seqlocw(int).

    Any ideas?

    Thanks for the Help!



    int seqlocw = 0;
    string swill;
    string pqr;
    string sfx;

    string sortline;
    int errors = 0;
    //
    //***********************************************
    //* Load SEQ Table *
    //***********************************************

    cout << "Enter Waste-file name without the extension - .clnt is assumed\n";
    cin >> pqr;
    def = "/jet/user/bmetros/";
    def += pqr;
    def += "-srt";
    def += ".txt";
    cout << "Enter Waste-file sequence number starting position\n";
    cin >> swill;
    cout << "Enter Waste-file sequence number starting position\n";
    cin >> seqlocw;
    cout << "swill = " << swill << endl;

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Code:
    #include <iostream>
    #include <sstream>
    #include <string>
    
    int main() {
       std::istringstream convTo;
       std::string strVal = "123";
       int numVal;
       
       convTo.str(strVal);  // convTo now contains the string "123"
       
       convTo >> numVal;   // Reads the buffer into the int appropriately
       
       std::cout << numVal + 2; // Some arithmetic to show this.
       std::cin.get();
       
       return 0;
    }
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 08:19 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  3. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM
  4. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM

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