Here is my code . . .
int iChoice; string sSafetyNetConversion; getline(cin,sSafetyNetConversion); if(sSafetyNetConversion=="1"||sSafetyNetConversion=="2")iChoice=sSafetyNetConversion;
Thank you for reading this




Posted 14 August 2011 - 03:05 AM
int iChoice; string sSafetyNetConversion; getline(cin,sSafetyNetConversion); if(sSafetyNetConversion=="1"||sSafetyNetConversion=="2")iChoice=sSafetyNetConversion;
Posted 14 August 2011 - 03:20 AM
#include <iostream>
#include <sstream>
int main(int argc, char* argv[])
{
//Our string
std::string s = "1234";
//Create the stringstream object
std::stringstream ss;
//Set the string in the stringstream object
ss.str(s);
int n;
//Convert the string from the stringstream to an integer
ss >> n;
std::cout << n << std::endl;
std::cin.get();
return 0;
}
Posted 14 August 2011 - 03:35 AM
#include <iostream>
int main(int argc, char* argv[])
{
//Our string
std::string s = "1234";
int n = atoi(s.c_str());
std::cout << n/2<< std::endl;
std::cin.get();
return 0;
}
This post has been edited by MathiasVP: 14 August 2011 - 03:37 AM
Posted 14 August 2011 - 03:38 AM
string sSafetyNetConversion; getline(cin,sSafetyNetConversion); stringstream ss; ss.str(sSafetyNetConversion); if(sSafetyNetConversion=="1"||sSafetyNetConversion=="2")iChoice>>ss;
Posted 14 August 2011 - 04:05 AM
Posted 14 August 2011 - 04:48 AM
PlasticineGuy, on 14 August 2011 - 07:05 AM, said:
Posted 14 August 2011 - 05:30 AM
bool parse(const std::string &s, int &n) {
std::stringstream ss(s);
return (ss>>n);
}
template<typename T>
bool parse(const std::string &s, T &n) {
std::stringstream ss(s);
return (ss>>n);
}
int iChoice;
string sSafetyNetConversion;
getline(cin,sSafetyNetConversion);
if(parse(sSafetyNetConversion, iChoice)) {
// now check the int
if (iChoice==1||iChoice==2) { /* */ }
} else {
/* bad data, you decide */
}
int parseOrDefault(const std::string &s, int n) {
std::stringstream ss(s);
ss>>n;
return n;
}
string sSafetyNetConversion;
getline(cin, sSafetyNetConversion);
int iChoice = parseOrDefault(sSafetyNetConversion, -1);
Posted 14 August 2011 - 09:39 AM
int iChoice; string sSafetyNetConversion; getline(cin,sSafetyNetConversion); if(sSafetyNetConversion=="1"||sSafetyNetConversion=="2") iChoice = stoi(sSafetyNetConversion);
This post has been edited by Ricky65: 14 August 2011 - 09:53 AM
Posted 14 August 2011 - 12:38 PM
#include <boost/lexical_cast.hpp>
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "123456"
int n = boost::lexical_cast<int> (s);
cout << n << endl;
cin.get();
return 0;
}
This post has been edited by alke4: 14 August 2011 - 12:41 PM
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
