• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Really simple(strings and spaces in C++)

Grazehell

2[H]4U
Joined
Jun 13, 2001
Messages
2,660
I want to enter a string with spaces and want the program to tell me what is size of the entire thing, not just up to the first space.

Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;




int main()

{

	string alpha;
	
	int alpha_len;

cout <<"Enter String with a space in between" <<endl;

cin>> alpha;

alpha_len = alpha.size();


cout<<"String lenght is "<<alpha_len<<endl;
 
system("PAUSE");

  
  return 0;
      }
 
Grazehell, since you're doing this as an academic excercise, I would recomment looking up information about buffer overflows and cin >>.
 
Grazehell, since you're doing this as an academic excercise, I would recomment looking up information about buffer overflows and cin >>.
As I understand it, buffer overflows would be applicable to character arrays but not to STL strings (which the OP uses).
 
yes, you are correct. as stated, it was for an academic exercise. my bet is that if he didn't know how to use cin.get() that also wasn't aware of the buffer overflow problem, which he's bound to encounter sometime.
 
yes, you are correct. as stated, it was for an academic exercise. my bet is that if he didn't know how to use cin.get() that also wasn't aware of the buffer overflow problem, which he's bound to encounter sometime.

I know about cin.get and it did not work here!
I accomplished what I set out to do, I am just working on a decent enough algorithm which is teaching me how to do exponentials and roots in C++
 
As someone who doesn't know much C++ I can only recommend that there is a lot more to be gained by learning what the different libraries do than by reinventing the wheel. cmath will do exponential and roots
 
As someone who doesn't know much C++ I can only recommend that there is a lot more to be gained by learning what the different libraries do than by reinventing the wheel. cmath will do exponential and roots

That's what I am using. But for some reason I am catching my butt.It would not necessarily be programming related problems but me trying to sort out my algorithm.
 
Back
Top