code doesn't allow input of user

the following code does not allow an input from the user..
the bold and italicised part is where i need help. oh! and i use code::blocks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
std::fstream afile;
std::string no1;
void Menu();
void func1();
  :
  :
int main()
{
Menu();
return 0
}
void Menu()
{
 :
 :
std::cout<<"enter no......"
std:cin>>no;
switch(no)
{
case 1 : func1();
         break;
   : 
   :
   :
}
}
void func1()
{
afile.open("file.dat", std::ios::out | std::ios::in);
std::cout<<"\n CREATE RECORDS \n \n Enter Record Number: ";
afile<<no1;
 :
 :
 :
 :
}
other functions
 :
 :
 :
Last edited on
someone please help ... i need to submit this project in two days...
the following code does not allow an input from the user..
the bold and italicised part is where i need help

But the "bold and italicised part" does not contain any use of cin. Hardly surprising that it doesn't allow any user input?
i want it to be added into the file

Yes, but what is "it"?

For example if it is a name, then you might do:
1
2
3
cout << "please enter name" << endl;
string name;
cin >> name;

or if it is a number, you could do:
1
2
3
cout << "please enter number" << endl;
int number;
cin >> number;

etc.
Last edited on
i want it to be added into the file... i searched it on Google and found this

http://www.tutorialspoint.com/cplusplus/cpp_files_streams.htm

can you please tell me where i went wrong?
the variable no i mean, i want that to be added into the file...
In the code above I see this:
std::string no1;
this creates an empty string called no1 with the contents "".

Then further down, afile<<no1;
Well, if an empty string is written to the file, then the file contents will not change, simply because the string is empty.

I'm not sure whether the code you posted has been edited to make it shorter and some of the important parts deleted, or whether it truly does represent the actual code.

But I would definitely expect to see the variable no1 be assigned some non-empty value before outputting it to the file, either by
cin >> no1;
or perhaps
getline(cin, no1);
... or from somewhere else...
Last edited on
ohh... thanks. i forgot to add that... thank you very much :D :D
Topic archived. No new replies allowed.