Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8885029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:12:34+00:00 2026-06-14T21:12:34+00:00

void docDB(){ int sdb = 0; ifstream dacb(kitudacbiet.txt); if(!dacb.is_open()) cout<<Deo doc dc file<<endl; else{

  • 0
void docDB(){
     int sdb = 0;
     ifstream dacb("kitudacbiet.txt");
     if(!dacb.is_open())
         cout<<"Deo doc dc file"<<endl;
     else{
          while(!dacb.eof()){
               dacb>>dbiet[sdb].kitu;
               dacb>>dbiet[sdb].mota;
               //getline(dacb,dbiet[sdb].mota);
               /*
               string a="";
               while((dacb>>a)!= '\n'){
                //strcat(dbiet[sdb].mota,a);
                dbiet[sdb].mota+=a;
               }
               */
               sdb++;
          }
     }

}

Text file: “kitudacbiet.txt”

\ Dau xuyet phai
@ Dau @
# Dau #
$ Ky hieu $
( Dau mo ngoac
) Dau dong ngoac

Screen

I want read firt string of line into dbiet[sdb].kitu and the rest of line into dbiet[sdb].mota

Example: line 1 = \ Dau xuyet phai

dbiet[sdb].kitu = “\” and dbiet[sdb].mota = “Dau xuyet phai”

I would like to read line by line until i met downline character (‘\n’). How to do this.
Sorry my english not good.Thank

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:12:35+00:00Added an answer on June 14, 2026 at 9:12 pm

    To read a whole line from a file into a string, use std::getline like so:

     std::ifstream file("my_file");
     std::string temp;
     std::getline(file, temp);
    

    You can do this in a loop to until the end of the file like so:

     std::ifstream file("my_file");
     std::string temp;
     while(std::getline(file, temp)) {
          //Do with temp
     }
    

    References

    http://en.cppreference.com/w/cpp/string/basic_string/getline

    http://en.cppreference.com/w/cpp/string/basic_string

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

void initializeVectorFromFile(vector<SInventory> & inven){ ifstream initData(inventoryData.txt); if(!initData){ cout << File could not be accessed!
void outputString(const string &ss) { cout << outputString(const string& ) + ss << endl;
void display(char * str){ printf(%s: Missing file\n, str); } int main(int argc, char **argv)
void display() { list *newlist; newlist = first; cout << endl; do { if
- (void)TargetHit:(int)target{ void (^threadBlock)(void) = ^{ NSLog(@respond to selector %d, [self respondsToSelector:@selector(changeImageOfTarget:)]); [[NSOperationQueue mainQueue]
void foo(Node* p[], int size){ _uint64 arr_of_values[_MAX_THREADS]; for (int i=0 ; i < size
void AFCQueue::ExtractValuesSecComplex(int startIndex, int endIndex,int helperIndex) { int size = 0,i,index; TimeType min_timestamp; bool
void sort(int a[], int b[], int m, int n) { int e = m
void swap(int a[], int size){ ............... } int main(){ int x[4] = {4,5,3,12} ;
void expand_combinations(const char *remaining_string, string const & s, int rema in_depth) { if(remain_depth==0) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.