howto multiply, ignore whitespace on cin

Whee... hello.
I'm compiling with Dev-C++'s default compiler (MingW, as I understand it), on Windows XP. I doubt either of these are significant, but oh well...
Two small problems here.

Firstly, multiplication:
Right now, I've got
1
2
3
4
5
char[9] pdat;
loadedfile.read(pdat, 9);
int tdat;
(start for loop)
tdat = pdat[x]*(2^7-x)

From what my friend says, my problem(getting seemingly non-sensical values) is asterisk's double-meaning, as multiplication and "pointer" (a concept I'm not familiar with).
If that's the case, how do I tell the compiler that I want to multiply?
If it's not the case... I'm getting non-zero results where pdat[x]=0, and non-powers of 2 where pdat[x]=1 (loadedfile is just a text document of 1s and 0s), and I have no idea what's going on.

Second, I have several places in my program where it cin's a string used for a filename. However, it breaks when encountering whitespace.
I've tried:
1
2
cin >> noskipws;
cin >> filename;

and
cin.get(filename);
as seem to be suggested wherever I found online, but the first one doesn't seem to make any difference, and the second makes my compiler angry ("108 C:\...\main.cpp no matching function for call to `std::basic_istream<char, std::char_traits<char> >::get(std::string&)' ")
1) 2^7 means 2 xor 7, use the pow function ( http://www.cplusplus.com/reference/clibrary/cmath/pow/ )
2) Try getline(cin,filename);, this reads until a newline character ( '\n' ) is found - you can change the delimiting character if you wish

1) 2^7 means 2 xor 7, use the pow function ( http://www.cplusplus.com/reference/clibrary/cmath/pow/ )

Ah, I thought of that, but also failed to find anything on powers in C++.
Nonetheless, that accounted for, I'm still getting some rather perplexing results.
1
2
    cout << pdat[x] << " ";
    cout << pdat[x]*pow(2.0, x) << " -- ";

yields:
0 48 -- 1 98 -- 0 192 -- 0 384 -- 0 768 -- 1 1568 -- 0 3072 -- 1 6272


2.
2) Try getline(cin,filename);, this reads until a newline character ( '\n' ) is found - you can change the delimiting character if you wish
1
2
3
4
5
  string newname;
  cout << "new filename:";
  getline(cin, newname);
(intermediate code)
cout << "finished.  Restarting...\n\n";

results in
new filename:finished. Restarting...


I'm inclined to think I'm missing something obvious on either of these, here, but...
1) Can you post some more code of that part? Those two lines should work

2) That is because you are getting input with >> before getline. Add cin.ignore(); before getline, it will remove the '\n' character that >> leaves on the stream. To get input from cin in a better way see http://www.cplusplus.com/forum/articles/6046/
1) Can you post some more code of that part? Those two lines should work
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
   if(cursel == 3){
  string newname;
  cout << "new filename:";
  cin.ignore;
  getline(cin, newname);
  ofstream newfile((curdir+newname).c_str());
    for(int runs = loadedsize/9; runs > 0; runs=runs-1){
   char pdat[9];
   loadedfile.read(pdat, 9);
   int tdat;
     for(int x = 0; x < 8; x = x+1){
    cout << pdat[x] << " ";
    cout << pdat[x]*pow(2.0, x) << " -- ";
     }
   cout << "\n";
   char udat = tdat;
   newfile << udat;
    }
   }


2) That is because you are getting input with >> before getline.

I'm not sure what you mean by that. There were no instances of >> in my program, after I did what you said.
Adding cin.ignore; gives me compile error: "statement cannot resolve address of overloaded function".
I'm not sure what's different in my code from what that in the article you linked (which I tried compiling and running; the article's code worked).
You forgot function parentheses after cin.ignore
And pdat[x] is a character, this means that you are doing operation on the ASCII values, not on the actual numbers ( eg '1' = 49 )

Topic archived. No new replies allowed.