Variables

closed account (SEbXoG1T)
I need a variable type that can store spaces, numbers and letters. any help would be good.
std::string? I'd suggest you to follow tutorials, that is really basic stuff you shouldn't bother people with.
closed account (SEbXoG1T)
tried that, string wouldn't accept spaces.
Of course it does. Spaces, tabs and stuff like that are all just characters, a string frankly doesn't care about spaces. The problem is probably rather with your input - I'll take a guess and say you use something like cin>>my_string?
Last edited on
closed account (SEbXoG1T)
yeah...

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

int main () {
string data;
ofstream myfile;
myfile.open ("example.txt");
cout<<"enter: ";
cin>>data
myfile <<data


myfile.close();
return 0;
}
Last edited on
cin>> stops at tabs and spaces and the like. Use getline(cin,my_string) if you want to read an entire line.
closed account (SEbXoG1T)
Thank you, it worked!!!!!!!
Last edited on
Topic archived. No new replies allowed.