Mar 24, 2011 at 9:21pm UTC
I need a variable type that can store spaces, numbers and letters. any help would be good.
Mar 24, 2011 at 9:22pm UTC
std::string? I'd suggest you to follow tutorials, that is really basic stuff you shouldn't bother people with.
Mar 24, 2011 at 9:23pm UTC
tried that, string wouldn't accept spaces.
Mar 24, 2011 at 9:24pm UTC
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 Mar 24, 2011 at 9:25pm UTC
Mar 24, 2011 at 9:25pm UTC
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 Mar 24, 2011 at 9:27pm UTC
Mar 24, 2011 at 9:27pm UTC
cin>> stops at tabs and spaces and the like. Use getline(cin,my_string)
if you want to read an entire line.
Mar 24, 2011 at 9:28pm UTC
Thank you, it worked!!!!!!!
Last edited on Mar 24, 2011 at 9:30pm UTC